Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

android - How to improve the performance of ViewFlipper/ViewAnimator

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>

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.

-Will any layout alternative to ViewAnimator (ViewPager, other implementations of ViewGroup...) improve anything?

-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 I use Canvas or GLSurfaceView? (cannot use the animation framework)

I'm stuck... can you help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To improve the performance of the ViewFlipper, you can set

android:measureAllChildren="false"

in the xml. This is normally set to false for FrameLayout, but ViewAnimator enables it by default for some reason.

Setting it to false solved a very strange lag-issue for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...