gpt4 book ai didi

android - 工具栏未显示在谷歌地图的 fragment 中

转载 作者:太空宇宙 更新时间:2023-11-03 12:51:54 27 4
gpt4 key购买 nike

我有一个 android fragment ,我将谷歌地图放入其中。我正在尝试在顶部添加一个 android 工具栏。

我的 xml 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/statsSpin"
android:spinnerMode="dropdown"/>


</android.support.v7.widget.Toolbar>

<!-- Lots of fancy layout -->

<RelativeLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>


</RelativeLayout>

当我运行我的应用程序时,android 工具栏没有显示...

我的 fragment 看起来像这样:

public class BreweryTappedMap extends Fragment {

public BreweryTappedMap(){}

String beerId = "";
GoogleMap mMap;

private SupportMapFragment fragment;
private GoogleMap map;
String userID;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.activity_brewmap, container, false);
((ActionBarActivity)getActivity()).getSupportActionBar().setTitle("Your Maps");

Spinner spinner = (Spinner) rootView.findViewById(R.id.statsSpin);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.mappage, R.layout.dropdown_item);
spinner.setAdapter(adapter);


spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {


switch (position) {
case 0:
break;
case 1:
// do whatever stuff you wanna do here
Fragment Fragment_one;
FragmentManager man= getActivity().getSupportFragmentManager();
FragmentTransaction tran = man.beginTransaction();
Fragment_one = new BreweryMap();
tran.replace(R.id.main, Fragment_one);//tran.
tran.addToBackStack(null);
tran.commit();
break;



}


}

@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}

});
//get user information
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
String userName = prefs.getString("userName", null);
userID = prefs.getString("userID", null);

//add url

//call async to get breweries to add to



return rootView;
}


@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
if (fragment == null) {
fragment = SupportMapFragment.newInstance();
fm.beginTransaction().replace(R.id.map, fragment).commit();
}
}

@Override
public void onResume() {
super.onResume();
if (map == null) {
map = fragment.getMap();
String url = "myURL";

new GetVisitedBreweries(getActivity(), map).execute(url); }
}
}

最佳答案

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/statsSpin"
android:spinnerMode="dropdown"/>


</android.support.v7.widget.Toolbar>

<!-- Lots of fancy layout -->

<RelativeLayout
android:id="@+id/map"
android:layout_below="@+id/toolbar" <----- You need this
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>


</RelativeLayout>

关于android - 工具栏未显示在谷歌地图的 fragment 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28967301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com