I. Setting frame animations in an XML file
1, first you have to create a animation_list file under the Drawable resource folder
<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/p1 " android:duration="/> <item android:drawable= "@drawable/p2" android:duration= "/> <item android:drawable=" @ Drawable/p3 " android:duration="/> <item android:drawable= "@drawable/p4" android: Duration= ""/> <item android:drawable= "@drawable/p5" android:duration= " Animation-list>
2. Load the animation into space via Java code startup and start
ImageView imageview= (ImageView) Findviewbyid (R.ID.ID_IV); Imageview.setimageresource (r.drawable.anim_list); Animationdrawable animationdrawable = (animationdrawable) image.getdrawable (); Animationdrawable.setoneshot (false) ;//Whether to execute only once Animationdrawable.start ();//Start animation//animationdrawable.stop ();//Stop animation
Second, set the frame animation in Java code
ImageView imageview= (ImageView) Findviewbyid (R.ID.ID_IV); animationdrawable= new Animationdrawable (); Animationdrawable.addframe (Getresources (). Getdrawable (R.DRAWABLE.P1), and Animationdrawable.addframe ( Getresources (). Getdrawable (R.DRAWABLE.P2), imageview.setimagedrawable (Animationdrawalbe); Animationdrawable.setoneshot (false);//whether to execute only once Animationdrawable.start ();//Start animation//animationdrawable.stop ();//Stop animation
Android Frame Animation