问题描述
我需要你们的帮助......我的工作,直到3天。我的应用程序正在与片段。其中一个片段能够显示从谷歌地图API V2为Android的地图。
目前,我使用的是MapFragment,但毫无疑问,在一个片段一个片段是不是一个好主意,但它的工作原理,地图上显示的是,我可以编辑,但是当我切换主片段和回报吧。
这是因为当我去另一个片段,并返回一个包含地图。我在寻找,直到3天,以解决这一问题,但没有很大的成绩。
要恢复你的,我有一个Activity这就要求包含在布局文件中的MapFragment一个片段。如果你需要更多的,只是问:)
感谢
编辑:这里是code改变片段的主要活动
私人无效swtichFragment(片段片段,捆绑包)
{
fragment.setBundle(本,捆绑);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.rightFragmentPlaceHolder,片段);
fragmentTransaction.commit();
mRightFragment =片段;
}
使用图形页面,而不是MapFragment在片段的布局。请记住调用图形页面的生命周期方法:
- 的onCreate(捆绑)
- 在onResume()
- 的onPause()
- 的onDestroy()
- 的onSaveInstanceState(捆绑)
- onLowMemory()
如here.
顺便说一句。你不应该使用MapFragment,只有SupportMapFragment和支持库。
编辑:
如果您切换到支持库,你可以使用从评论#1这里code:<一href="http://$c$c.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1">http://$c$c.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1
I need your help... I work on it until 3 days. My app is working with fragments.One of these fragments has to display a map from the Google Maps V2 api for Android.
Currently, I'm using a MapFragment, but no surprise, a fragment in a fragment is not a good idea, but it works, the map is displaying, i can edit it but when I switch of main fragment and return on it.
This is the cause when I go on another fragment and return to the one which contains the map.I'm searching until 3 days to fix this but no great results.
To resume for you, I've an Activity which calls a fragment which contains a MapFragment in the layout file.If you need more, just ask :)
Thanks
Edit : Here is the code to change Fragment in the main Activity
private void swtichFragment(Fragment fragment, Bundle bundle)
{
fragment.setBundle(this, bundle);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.rightFragmentPlaceHolder, fragment);
fragmentTransaction.commit();
mRightFragment = fragment;
}
Use MapView instead of MapFragment in your Fragment's layout. Remember to call MapView's lifecycle methods:
- onCreate(Bundle)
- onResume()
- onPause()
- onDestroy()
- onSaveInstanceState(Bundle)
- onLowMemory()
as described here.
Btw. you shouldn't be using MapFragment, only SupportMapFragment and support library.
Edit:
If you switch to support library, you can use code from comment #1 here:http://code.google.com/p/gmaps-api-issues/issues/detail?id=5064#c1
这篇关于MapFragment的片段,替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!