Multiple maps v2 in TabActivity

ε祈祈猫儿з 提交于 2019-11-28 23:01:51

问题


I'm currently trying to have 2 maps v2 in different tabs of a TabActivity using MapView objects. The problem arises in the following scenario:

  • tab1 with a map is displayed
  • go to tab2 in order to display another map
  • in this second tab looks like the map image from first tab is overlapping the new map. See the following picture:

On the right you can see how the first map is still displayed on top of it. The touch events are going to the new map but that doesn't really help. I spent a lot of time trying to convert our app to use fragments and run into other types of issues. One of them being http://code.google.com/p/android/issues/detail?id=40035 so that's not a good option either.

So far I haven't been able to find any workaround. To easily try various changes I wrote a simple application and made it available here: https://github.com/cristizmf/TestMapsV2. It needs only the right location for maps library project and a good maps key in manifest.

Any ideas would be greatly appreciated.

Later edit: I've logged an issue for this: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5027&thanks=5027&ts=1362071369


回答1:


We are having the exact same problem. I suspect this is caused by the fact that the new maps uses OpenGL - possibly android cant deal with having two OpenGL widgets in the view hierarchy at the same time even though one is hidden.

The only way we worked around this was to actually remove the mapview when leaving a tab, then construct a new one and add it back in when going back into the tab. This ensures that there are never two maps constructed at once.

Nasty, but it worked.




回答2:


I ran into the same issue a few days ago and was pulling my hair out over what to do.

Originally I had my app set up with "Tabs the Fragment way" as seen here to avoid the deprecated TabActivity, and used this hack to allow me to incorporate Maps v1 in with the Fragments. It basically just masks an Activity as a Fragment.

But then switched to TabActivity further down the track for simplicity / it was better suited for the whole app. But now obviously this 2x Maps v2 fragment problem has become an issue..

So I have reverted back to "Tabs with Fragments" and just have the "hack setup" as mentioned above for each tab, which allows to have an Activity for each tab, AND having more than one Maps v2 displaying for each Tab. I haven't gone into too much depth with it, but it seems to be doing the job atm, with having just thrown some code together to test it out..

Don't know if you're still having an issue with this / this obviously isn't the most correct solution, but just thought I'd share my two cents incase you still needed it.

Cheers.



来源:https://stackoverflow.com/questions/14585409/multiple-maps-v2-in-tabactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!