Layout file 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"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Android:background= "#000000"Tools:context=". Mainactivity " > <ImageViewAndroid:id= "@+id/imageview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /></Relativelayout>
Mainactivity.java
Packagecom.playgif;Importandroid.app.Activity;Importandroid.graphics.drawable.AnimationDrawable;ImportAndroid.os.Bundle;ImportAndroid.widget.ImageView; Public classMainactivityextendsActivity {ImageView ImageView=NULL; animationdrawable Animation=NULL;; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); ImageView=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1); Imageview.setbackgroundresource (r.drawable.img_list); Animation=(animationdrawable) imageview.getbackground (); //whether to start only onceAnimation.setoneshot (false); if(Animation.isrunning ()){animation.stop ();//Stop} animation.start ();//Start }}
Img_list.xml
<?XML version= "1.0" encoding= "Utf-8"?><animation-listxmlns:android= "Http://schemas.android.com/apk/res/android" > <Itemandroid:drawable= "@drawable/a1"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a2"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a3"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a4"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a5"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a6"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a7"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a8"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a9"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a10"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a11"android:duration= "+" /> <Itemandroid:drawable= "@drawable/a12"android:duration= "+" /> </animation-list>
Android:duration refers to the delay in which the pictures to be polled are added to the list.