MapFragment的片段,替代品? [英] MapFragment in Fragment, alternatives?

查看:271
本文介绍了MapFragment的片段,替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你们的帮助......我的工作,直到3天。我的应用程序正在与片段。 其中一个片段能够显示从谷歌地图API V2为Android的地图。

目前,我使用的是MapFragment,但毫无疑问,在一个片段一个片段是不是一个好主意,但它的工作原理,地图上显示的是,我可以编辑,但是当我切换主片段和回报吧。

  

致:java.lang.IllegalArgumentException:如果二进制XML文件中的行#59:重复ID 0x7f070041,标记为空,或父母身份证0x7f070040与另一个片段com.google.android.gms.maps.MapFragment

     

在android.app.Activity.onCreateView(Activity.java:4252)

     

在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)

这是因为当我去另一个片段,并返回一个包含地图。 我在寻找,直到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()

如<一个href="https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapView">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.

Caused by: java.lang.IllegalArgumentException: Binary XML file line #59: Duplicate id 0x7f070041, tag null, or parent id 0x7f070040 with another fragment for com.google.android.gms.maps.MapFragment

at android.app.Activity.onCreateView(Activity.java:4252)

at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673)

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的片段,替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆