I have created an AnimationDrawable and i want to repeat that animation for infinite number and stop that animation on a button click, i am sharing my code
anim.xml file
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true" >
<item android:drawable="@drawable/download_anim1" android:duration="100" />
<item android:drawable="@drawable/download_anim2" android:duration="100" />
<item android:drawable="@drawable/download_anim3" android:duration="100" />
<item android:drawable="@drawable/download_anim4" android:duration="100" />
<item android:drawable="@drawable/download_anim5" android:duration="100" />
</animation-list>
in my layout file
<ImageView
android:id="@+id/imageViewAnimation"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:padding="3dp"
android:layout_marginBottom="10dp"
android:layout_weight="2"
android:background="@color/colorOrange"
android:src="@drawable/anim" />
and in my activity where i have started my animation
ImageView imageViewAnimationr = (ImageView) headerView.findViewById(R.id.imageViewHeaderDownloadAnimation);
AnimationDrawable animationDrawable = (AnimationDrawable) imageViewAnimationr.getDrawable();
animationDrawable.start();