我已经成功实现了地图,但我找不到任何与此相关的帮助,这是我对谷歌地图片段的实现
SupportMapFragment fragment;
private GoogleMap map;
FragmentManager fm;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FragmentManager fm = getChildFragmentManager();
fragment = (SupportMapFragment) fm.findFragmentById(R.id.mapLarge);
if (fragment == null) {
fragment = SupportMapFragment.newInstance();
fragment.setRetainInstance(true);
fm.beginTransaction().replace(R.id.mapLarge, fragment).commit();
}
}
@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (map == null) {
System.out.println("map is null");
map = fragment.getMap();
}
我正在以编程方式添加地图片段(在 Actionbar.Tab 中显示地图视图的解决方法)
任何帮助将不胜感激 !
这是我的答案,它可能会对某人有所帮助。我所做的是将工具栏放在里面CoordinatorLayout
并应用了一些余量AppBarLayout
.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MapActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:theme="@style/AppTheme.AppBarOverlay">
<include layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
以下是上述代码的输出。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)