Recommended way to make animation in Android
I've searched around the web to learn more about animating a character in Android but didn't fully understo开发者_StackOverflow中文版od it. I ask here maybe you could give me some advices or hints on how to make it in the best possible way.
Scenario
Imagine 5 drawn characters (let's say 5 human heads). I need to animate them. By animation I mean make eyes blink, smile, laugh etc. Right now I am working on making bitmap resources on each animation. For example for the blink animation, basically I have 3 images, one with eyes open, one with eyes half closed, one with eyes closed. I need to animate the character to use all these 3 images.
This is all the animation I need, nothing more fancier. Any suggestions from where to start ?
AnimationDrawable frameAnimation;
frameAnimation = (AnimationDrawable) addselection.getBackground();
@Override
public void onWindowFocusChanged(boolean hasFocus) {
frameAnimation.start();
super.onWindowFocusChanged(hasFocus);
}
add drawable using this type of xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/add_selection0001" android:duration="50" />
<item android:drawable="@drawable/add_selection0002" android:duration="50" />
<item android:drawable="@drawable/add_selection0003" android:duration="50" />
<item android:drawable="@drawable/add_selection0004" android:duration="50" />
<item android:drawable="@drawable/add_selection0005" android:duration="50" />
<item android:drawable="@drawable/add_selection0006" android:duration="50" />
<item android:drawable="@drawable/add_selection0007" android:duration="50" />
<item android:drawable="@drawable/add_selection0008" android:duration="50" />
<item android:drawable="@drawable/add_selection0009" android:duration="50" />
<item android:drawable="@drawable/add_selection0010" android:duration="50" />
<item android:drawable="@drawable/add_selection0011" android:duration="50" />
<item android:drawable="@drawable/add_selection0012" android:duration="50" />
<item android:drawable="@drawable/add_selection0013" android:duration="50" />
<item android:drawable="@drawable/add_selection0014" android:duration="50" />
<item android:drawable="@drawable/add_selection0015" android:duration="50" />
<item android:drawable="@drawable/add_selection0016" android:duration="50" />
<item android:drawable="@drawable/add_selection0017" android:duration="50" />
<item android:drawable="@drawable/add_selection0018" android:duration="50" />
<item android:drawable="@drawable/add_selection0019" android:duration="50" />
<item android:drawable="@drawable/add_selection0020" android:duration="50" />
</animation-list>
here set different images for your sequence animation.set this drawable as your background in imageview
Just to get you going you can try Frame Animation, it's part of the basic Animation package within Android, there is a relatively simple example on the official docs website here: http://developer.android.com/guide/topics/resources/animation-resource.html#Frame.
If you need more control of the animation you'll need to look in to using the SurfaceView or Canvas and do the drawing (animation) yourself. That's not too difficult either but your needs will dictate what the best thing to do is. So try the Frame Animation first, if you find it's too limiting post back and I (or some one else) can help you to get going with SurfaceView.
精彩评论