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