A simple example of animationdrawable used in Android _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.