多MapFragments性能(Android的地图API第2版)性能、地图、MapFragments、API

2023-09-06 04:33:24 作者:淡漠人情炎凉﹠

我找遍了新的谷歌Android地图API V2 的文档,但没找不到任何关于它。 V2之前,我们(官方)无法正常显示每个应用程序(进程)以上的地图。我认为与 MapFragment 实施它不再是一个问题。我也知道,片段可以是自包含的,因为API 17.最后但并非最不重要的,有兼容包,这使得它可以将它移植全部恢复至少API 8(在​​API 7,没有的OpenGL 2.0这样的地图是行不通据我所知)。

I searched the docs of the new Google Android Map API v2, but didn't find anything about it. Before v2 we (officially) couldn't properly display more than one map per application (process). I assume that with MapFragment implementation it's no longer an issue. I also know, that Fragments can be self-contained since API 17. And, last but not least, there is compatibility package, which makes it possible to port it all back to at least API 8 (in API 7, there's no OpenGL 2.0 so the maps wouldn't work afaik).

萨我把所有的成分,口我的应用程序,以地图API v2和实施以下情形: ViewPager 包含片段和他们每个人都包含一个 MapFragment

Sa I have all the ingredients to port my app to Maps API v2 and implement the following scenario: ViewPager contains Fragments and each of them contains a MapFragment.

不过,我应该怎么办呢?我的意思是,我会面临性能问题如果我有,例如20 片段包含 MapFragments ViewPager

But should I do it? I mean, would I face performance issues if I had e.g. 20 Fragments containing MapFragments in a ViewPager?

如果你发现任何解决我的文档或其他地方的关注,请告诉我。

If you found anything that addresses my concern in the docs or somewhere else, please tell me.

编辑:用法示例:让我们想象一下包含一些特定的项目信息屏幕 - 地点,事件,物品。也让我们想象一下,其他信息中,它必须包含一个地图的全部功能。不过,我想用户能够刷到另一个项目,如果他想。每个项目都有其自己的地图。

Example usage: Let's imagine a screen containing informations about some specific item - place, event, article. Also let's imagine that, among other informations, it must contain a map to be fully functional. But I would like the user to be able to swipe to another item if he wants. Each item has its own map.

附注:我知道,我可以实现一个地图外 ViewPager ,只是它根据当前显示的项目更新,但它不是我要找的 - 它不是以用户为中心的设计

Side note: I know that I can implement one map outside the ViewPager and just update it based on the currently displayed item, but it's not what I'm looking for - it's not user-centered design.

可能的解决方法(但没有检查过)。 ViewPager 只保留少数(默认 - 3)碎片在它的高速缓存,并重新创建他们时,他们将要展现出来,所以不会有太大的内存开销,因为只有几个 MapFragments 是必要的。性能问题可能是 MapFragment 通货膨胀这是相当沉重的,我相信 - 但可以回收 MapFragments 。

Possible solution (but not checked yet). ViewPager only keeps a few (default - 3) Fragments in it's cache and recreates them when they're about to show up, so there won't be much memory overhead as only a few MapFragments are needed. The performance problem may be the MapFragment inflation which is quite heavy, I believe - but that can be solved with recycling of MapFragments.

那么,为什么不能我实现它,如果我相信它会工作的很好吗?还有另外一个问题,这使得它无法移动 MapFragments 没有应用程序看上去像是打碎了。 See这。

So why won't I implement it if I believe it will work nice? There's another problem which makes it impossible to move MapFragments without the app look like it's broken. See this.

推荐答案

是的,你肯定会遇到性能问题,因为 ViewPager 默认情况下不使用视图循环利用;你甚至可以用膨胀它的ImageView 取值更不用说MapFragments。

Yes, you definitely would run into performance issues because ViewPager doesn't employ view recycling by default; you can even bloat it with ImageViews let alone MapFragments.

据缓存和重新片段 ViewPager - 有一个的 Horizo​​ntalListView LIB下很可能节省您的精力,因为它不支持视图循环。

As far as caching and recreating fragments in ViewPager - there's a HorizontalListView lib that'd probably save you the effort as it does support view recycling.

 
精彩推荐
图片推荐