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.