The XML code of the frame-wise animation:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:oneshot= "true" >4 5 <Item6 android:drawable= "@drawable/img10"7 android:duration= "+">8 </Item>9 <ItemTen android:drawable= "@drawable/img9" One android:duration= "+"> A </Item> - <Item - android:drawable= "@drawable/img8" the android:duration= "+"> - </Item> - <Item - android:drawable= "@drawable/img7" + android:duration= "+"> - </Item> + <Item A android:drawable= "@drawable/img6" at android:duration= "+"> - </Item> - <Item - android:drawable= "@drawable/img5" - android:duration= "+"> - </Item> in <Item - android:drawable= "@drawable/img4" to android:duration= "+"> + </Item> - <Item the android:drawable= "@drawable/img3" * android:duration= "+"> $ </Item>Panax Notoginseng <Item - android:drawable= "@drawable/img2" the android:duration= "+"> + </Item> A <Item the android:drawable= "@drawable/img1" + android:duration= "+"> - </Item> $ <Item $ android:drawable= "@drawable/img0" - android:duration= "+"> - </Item> the - </animation-list>
View Code
The corresponding Android code:
Description:
- Android:oneshot: The number of times the frame animation runs, true to run once, and false to play the loop;
- Item: Defines the properties of each frame;
- Android:drawable: Specifies the image resource corresponding to the frame;
- Android:duration: The time at which the frame image stays.
1 Public classMainactivityextendsActivity {2 3 PrivateImageView img;4 Privatebutton button;5 Privateanimationdrawable animationdrawable;6 @Override7 protected voidonCreate (Bundle savedinstancestate) {8 Super. OnCreate (savedinstancestate);9 Setcontentview (r.layout.activity_main);Ten intduration=0;//duration is the total time to record the first animation play Oneimg=(ImageView) Findviewbyid (R.id.imageview); A Img.setimageresource (R.drawable.item_anim); -animationdrawable=(animationdrawable) img.getdrawable (); -Img.post (NewRunnable () {//method to execute startup in an asynchronous thread the - @Override - Public voidrun () { - //TODO auto-generated Method Stub + Animationdrawable.start (); Start Animation - } + }); A for(intI=0;i<animationdrawable.getnumberofframes (); i++){ atduration+=animationdrawable.getduration (i); Calculate when an animation plays - - } -Handler handler=NewHandler (); -Handler.postdelayed (NewRunnable () { - Public voidrun () { inIntent intent=NewIntent (mainactivity. This, Testactivity.class); Intent intent to jump to another page when the animation is done - startactivity (intent); to + } - }, duration); the * } $ Panax Notoginseng -}