开发者

ImageView performance - should it be redrawing when something in front of it changes?

I have an activity that uses a FrameLayout to draw two layers to the screen. The first, in back, is an ImageView displaying a bitmap - scaled to the full screen size with match_parent. The second, in front, is a small drawable implemented with animation-list - essentially a set of PNG frames that make up an animated icon (roughly 10 frames, with android:duration=100 ms each). The PNG images in the animation use transparency, so you can see the background ImageView behind it, and the whole thing is small relative to the ImageView - it really is effectively an icon on top of an image.

I've noticed that this simple application seems to use quite a bit of CPU power. To help track it down, I extended ImageView to override onD开发者_高级运维raw for the background image, and found that the onDraw routine appears to be called everytime the foreground animation updates. Is this expected behavior? I would expect that the ImageView contents should be getting cached somewhere so it doesn't have to redraw its bitmap if nothing changes.

Is there a better way to go about getting this functionality?


What you are seeing is expected. To redraw the PNGs you are animating, the framebuffer has to be cleared, which means the background ImageView must be redrawn. Caching would not help in any way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜