Better way to implement flipbook-style animation?
I'm using a handler
to simply post at delayed intervals, cycle through an array of drawable resources and set the imageResource
accordingly. It works just fine, but the "animation" is not super smooth. 开发者_开发技巧Is there some other way to implement this type of animation, where I just flip through images like a flipbook?
What you want is called a "Frame Animation" in Android. The images and the time to display each on screen is defined in an XML file. See the link below for details:
http://developer.android.com/guide/topics/resources/animation-resource.html#Frame
Here is how I have it running in a quick test app I wrote:
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.imageView1);
rocketImage.setBackgroundResource(R.drawable.jena);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
Then, inside of my drawable folder I have jena.xml:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/jenaveve0000" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0001" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0002" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0003" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0004" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0005" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0006" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0007" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0008" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0031" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0032" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0033" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0034" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0035" android:duration="500"/>
<item android:drawable="@drawable/jenaveve0036" android:duration="500"/>
</animation-list>
To start the animation I have:
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
rocketAnimation.start();
Please take a look as below: http://code.google.com/p/android-page-curl/
I think this page curl effect is great.
精彩评论