如何改善ViewFlipper / ViewAnimator的性能 [英] How to improve the performance of ViewFlipper/ViewAnimator
问题描述
我使用的 ViewAnimator (父类中的 ViewFlipper )做出某种互动的书。 层次结构大致是这样的:
I'm using a ViewAnimator (parent class of ViewFlipper) to make some kind of interactive book. The hierarchy is roughly like this:
<ViewAnimator>
<include layout="@layout/p0" />
<include layout="@layout/p1" />
<include layout="@layout/p2" />
...
</ViewAnimator>
所以书的页是ViewAnimator内部。每一页都有与动画ImageViews,TextViews,按钮...多层的这竟然是太多的FrameLayout。显示这本书通过viewAnimator.showNext一个新的页面()可以采取秒。所有的时间都用在ImageView.onDraw()-Traceview。
So the pages of the book are inside the ViewAnimator. Each page has a FrameLayout with multiple layers of animated ImageViews, TextViews, Buttons... which turned out to be too much. Displaying a new page of the book via viewAnimator.showNext() can take seconds. All that time is spent in ImageView.onDraw() -Traceview.
- 将会任何布局的替代ViewAnimator (ViewPager,ViewGroup中的其它实现......)改善什么?
-Will any layout alternative to ViewAnimator (ViewPager, other implementations of ViewGroup...) improve anything?
-Is有没有办法为 preLOAD的意见 ViewFlipper / ViewAnimator /等将展示下? (因此,这本书的下一个页面随时准备和乐意在内存中)
-Is there any way to preload the views a ViewFlipper/ViewAnimator/other will show next? (so that the next page of the book is always ready and happy in memory)
-Should我用帆布或GLSurfaceView? (不能使用动画框架)
-Should I use Canvas or GLSurfaceView? (cannot use the animation framework)
我卡住了...你能帮忙吗?
I'm stuck... can you help?
推荐答案
我不能回答你所有的问题,但我会给你我所知道的,因为它比缺乏其他的答案更好。 :P
I can't answer all your questions, but I'll give you what I know since it is better than the lack of other answers. :P
ViewPagers默认加载任何一方的意见。这加快了开关,但可能会降低当前打开的视图。对一个viewpager preloaded视图的数目可使用它的方法来设置。
ViewPagers load the views on either side by default. This speeds the switch, but might slow the view that is currently open. The number of preloaded views on a viewpager can be set using one of its methods.
如果你不想ViewPager,你可以尝试真正实例你想preloaded自己的看法,并简单地将它们设置为不可见。
If you don't want a ViewPager, you might try actually instantiating the views you want preloaded yourself, and simply setting them to invisible.
我没有经历过的帆布或GL除了地图叠加,但我希望他们可以更快/响应/有效的,如果实施得当,因为你不会有任何不必要的功能。也许是凌乱的,虽然,这取决于你的内容的来源。
I am not experienced with the canvas or GL besides map overlays, but I expect that they COULD be much quicker/responsive/efficient if properly implemented since you wouldn't have any unneeded functionality. Might be messy though, depending on the source of your content.
建议: 尝试ViewPager,它是由像您实现。如果你不满意它,卷起你的袖子,检查到画布上的东西。
RECOMMENDATION: Try the ViewPager, it is made for implementations like yours. If you are unsatisfied with it, roll up your sleeves and check into canvas stuff.
这篇关于如何改善ViewFlipper / ViewAnimator的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!