First, you can define an XML file under the Drawable folder. As shown below:
Copy Code code as follows:
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:oneshot= "true" >
<item android:drawable= "@drawable/compass_1" android:duration= "/>"
<item android:drawable= "@drawable/compass_2" android:duration= "/>"
<item android:drawable= "@drawable/compass_3" android:duration= "/>"
<item android:drawable= "@drawable/compass_4" android:duration= "/>"
<item android:drawable= "@drawable/compass_5" android:duration= "/>"
</animation-list>
The root tag is animation-list, where the oneshot represents whether it is displayed only once, and set to False to loop the animation continuously. Where each item is a frame, android:duration= "400" means that each frame lasts 400ms,android:drawable the picture to be displayed per frame.
Next, the code uses:
Copy Code code as follows:
Animationdrawable ad = (animationdrawable) getresources (). getdrawable (r.drawable.bootanimation);
Get the Animationdrawable object. The object is then set to the backgroud of the current view.
Copy Code code as follows:
Mview.setbackgrounddrawable (AD);
You can then invoke the Ad.start () method and the Ad.stop () method to start and stop the animation.
Note: You must set the background for the current view, otherwise start and stop will have no effect on the animation.