Example of how Android plays animations

Source: Internet
Author: User

Today began to tidy up some of the regular Android common development utility.

First season: an example of how Android plays animations

1. Animation is usually GIF image, it is recommended to use the Easygifanimator tool to disassemble it as multiple images, the proposal is PNG;

2. Add the Anim directory under the Res directory of the Android project and create a new XML file, such as Loading.xml:

<?xml version= "1.0" encoding= "Utf-8"?>
<animation-list android:oneshot= "false"
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:duration= "android:drawable=" @drawable/loading0 "/>
<item android:duration= "android:drawable=" @drawable/loading1 "/>
<item android:duration= "android:drawable=" @drawable/loading2 "/>
<item android:duration= "android:drawable=" @drawable/loading3 "/>
</animation-list>

3. There are two ways to set the ImageView to play:

A. Imageview.setimageresourceid (r.anim.loading)

B. Imageview.setbackgroundsourceid (r.anim.loading)

4. Start the animation at the right time

Object OB = null;
Animationdrawable anim = null;
OB = imageview. getdrawable ();
if (ob! = null) {
Anim = (animationdrawable) ob;
Anim.stop ();
Anim.start ();
}

5. The above steps are basically completed, in particular, if not click Trigger, get ImageView instance can use static variable way

For example, in the click to get ImageView, put in a shareable global static inside, so that with handler or thread can be accessed

The above code in the application of IELTS heard "http://openbox.mobilem.360.cn/index/d/sid/2504749" in the use of English radio function, that is, when the user clicks on the playback of the display loading animation, start playing when the display of the radio animation

Example of how Android plays animations

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.