Anim/fat_po.xml
<?XML version= "1.0" encoding= "Utf-8"?><!--Specify the animation loop to play -<animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"Android:oneshot= "false"> <!--Add multiple Frames - <Itemandroid:drawable= "@drawable/fat_po_f01"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f02"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f03"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f04"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f05"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f06"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f07"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f08"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f09"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f10"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f11"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f12"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f13"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f14"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f15"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f16"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f17"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f18"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f19"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f20"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f21"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f22"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f23"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f24"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f25"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f26"android:duration= "$" /> <Itemandroid:drawable= "@drawable/fat_po_f27"android:duration= "$" /> </animation-list>
View Code
Mainactivity.java
Public classMainactivityextendsActivityImplementsonclicklistener{ImageView IV; Animationdrawable Draw; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); IV=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1); Draw=(animationdrawable) iv.getdrawable (); Draw.stop (); Button BTN1=(Button) Findviewbyid (R.id.button1); Button btn2=(Button) Findviewbyid (R.id.button2); Btn1.setonclicklistener ( This); Btn2.setonclicklistener ( This); } Public voidOnClick (View v) {if(v==Findviewbyid (R.id.button1)) {Draw.start (); }Else if(v==Findviewbyid (R.id.button2)) {draw.stop ();; } }}
View Code
Activity_main.xml
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "${relativepackage}.${activityclass}" > <ImageViewAndroid:id= "@+id/imageview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"android:src= "@anim/fat_po" /> <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_below= "@+id/imageview1"Android:layout_marginleft= "10DP"Android:layout_margintop= "16DP"Android:text= "Start" /> <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignbaseline= "@+id/button1"Android:layout_alignbottom= "@+id/button1"Android:layout_alignright= "@+id/imageview1"Android:text= "Stop" /></Relativelayout>
View Code
Android Learning-image processing-frames-by-frame animation