The AbsoluteLayout class (and cont开发者_开发问答ained LayoutParams class with x and y properties) is deprecated. While it is possible to roll my own class that extends ViewGroup and enables me to control the absolute positioning of the child views - is this the best approach for sprite animation?
First of all, I've made the assumption that moving ImageViews around by changing their x and y position will be more efficient than redrawing bitmaps inside a SurfaceView. Is this assumption right?
My wider question is really: what is the best approach for animating sprites in Android?
To answer the first question: you can use FrameLayout instead. It's the simplest of all layout managers and simply slaps all children into the top left corner. You can translate them using the offsetTopAndBottom()
and offsetLeftAndRight()
functions defined on View
. Alternatively, the layout parameters for FrameLayout support setting margins. Droid-Fu uses this technique to place sticky views on the screen. Here's the source code.
As to your other question, I assume you mean animations based on key frames. Frame animations are documented here.
I find that redrawing bitmaps in a SurfaceView to be more viable if your animation consists of only a few frames. So it depends on what kind of animation you are doing.
精彩评论