Example of how to play an animation on Android

Source: Internet
Author: User

Example of how to play an animation on Android

Today, I began to sort out some common Android development utilities.

Season 1: example of how to play an Android Animation

1. Generally, animations are gif images. We recommend that you use easygifanimator to split them into multiple images. We recommend that you use png;

2. Add the anim directory under the res directory of the Android project and create an xml file, such as loading. xml:


Xmlns: android = www.bkjia.com




 

3. Set the ImageView to be played in two ways:

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 preceding steps are completed. Specifically, if you do not click to trigger the operation, you can use static variables to obtain the imageview instance.

For example, you can get the imageview when you click it and put it in a shared global static file. In this way, you can access the image by using handler or thread.

The above code is used in the function of playing an English radio station in the application of IELTS listening to [http://openbox.mobilem.360.cn/index/d/sid/2504749]. That is, when a user clicks play, the animation of the playing station is displayed.

 

Related Article

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.