下面列出的是我的基本code控制图。我做了一些非常先进的东西后。一切似乎都在努力完善,直到 onResume()
。
下面是布局,您可以通过1单一的活动应用程序导航,有多个片段。这 mapFragment
包含在片段里。这工作得很好。然而,当我加入另一个片段,推动这一项就后退堆栈,当我回来稍后,地图是反应迟钝。
我试图通过移动我的呼吁 setupMaps()固定这一点;
到 onResume()
,然而这引起 GMaps实现。
当我从 GMaps实现= mapFragment.getMap(让它为空);
在 setViews()
。
我应该如何处理呢?
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState)
{
根= inflater.inflate(R.layout.fragment_maps,集装箱,假);
setupMaps();
返回根;
}
私人无效setupMaps()
{
GMaps实现= NULL;
FM = getActivity()getSupportFragmentManager()。
mapFragment = SupportMapFragment.newInstance();
android.support.v4.app.FragmentTransaction交易= getChildFragmentManager()的BeginTransaction()。
transaction.add(R.id.flMapContainer,mapFragment).commit();
}
@覆盖
公共无效onResume()
{
super.onResume();
mapFragment.onResume();
setViews();
}
私人无效setViews()
{
GMaps实现= mapFragment.getMap();
的getData(); //初始化覆盖,标志,多边形等。
}
@覆盖
公共无效的onPause()
{
mapFragment.onPause();
super.onPause();
}
解决方案
你看到你的logcat的东西吗?我以前有过这样的一些问题,我相信这是与旧的地图碎片的看法不是从其父的ViewGroup删除创建的一个新实例之前。这导致了误差关于一个重复片段。
尝试删除从flMapContainer的所有视图创建SupportMapFragment的新实例之前。
Listed below is my basic code for controlling the maps. I do some really advanced stuff later. Everything seems to work perfect, until onResume()
.
Here is the layout, you navigate through the app in 1 single activity, with multiple fragments. This mapFragment
is contained inside of a fragment. This works fine. However when I add another fragment and push this one on the back stack, when i come back to it later, the map is unresponsive.
I tried fixing this by moving my call to setupMaps();
into the onResume()
, however this caused gMaps
to be null when I get it from gMaps = mapFragment.getMap();
in the setViews()
.
How should I handle this?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
root = inflater.inflate(R.layout.fragment_maps, container, false);
setupMaps();
return root;
}
private void setupMaps()
{
gMaps = null;
fm = getActivity().getSupportFragmentManager();
mapFragment = SupportMapFragment.newInstance();
android.support.v4.app.FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.flMapContainer, mapFragment).commit();
}
@Override
public void onResume()
{
super.onResume();
mapFragment.onResume();
setViews();
}
private void setViews()
{
gMaps = mapFragment.getMap();
getData(); // initializes overlays, markers, polygons etc.
}
@Override
public void onPause()
{
mapFragment.onPause();
super.onPause();
}
解决方案
Do you see anything in your logcat? I've had some issues like this before, and I believe it was related to the old map fragment's View not being removed from its parent ViewGroup before creating a new instance of it. This resulted in errors regarding a duplicate fragment.
Try removing all views from your flMapContainer before you create the new instance of the SupportMapFragment.
相关推荐
最新文章