【发布时间】:2015-04-25 06:58:37
【问题描述】:
我刚刚切换到最新版本的 android-maps-extensions (2.2.0) 以及最新的 Play Services (6.5.87) 和支持库 (21.0.3)。 现在我不能重复使用我的 MapFragment。
我有带 NavigationDrawer 的 MainActivity。其中一个片段是内部带有 GoogleMap 片段的片段。当我在 NavigationDrawer 中的片段之间切换时,它们会重新创建自己。以前我为此使用了非常简单的解决方案。我使用了已经膨胀的视图:
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
return view;
}
view = inflater.inflate(R.layout.fragment_map, container, false);
SupportMapFragment mapFragment = SupportMapFragment.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.container, mapFragment).commit();
mapFragment.getExtendedMapAsync(new OnMapReadyCallback() {
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
setupMap();
}
});
return view;
}
但现在它不起作用。此片段第二次打开时地图不显示。
我可以扔掉这个丑陋的代码
if (view != null) {
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
return view;
}
并且总是在内部重新创建视图。但是我有数千个标记(当然还有很棒的聚类),并且需要很长时间才能重新绘制它们。
我知道这不是扩展库的问题,谷歌地图也有同样的行为。但也许你知道正确的决定?
【问题讨论】:
-
这里有同样的问题。似乎是播放库错误。
标签: android-maps-v2 android-maps android-maps-extensions