Android: How can I stop an infinite animation applied on an ImageView?

kiki picture kiki · Oct 12, 2010 · Viewed 44k times · Source

I have an ImageView on which I have applied a rotate animation. Since I want the rotation to go on continuously, I gave the repeatCount as infinite in my rotate.xml:

android:repeatCount="infinite"

In onCreate(), I load the animation and start it.

Animation myAnim    = AnimationUtils.loadAnimation(this, R.anim.rotate);
objectImg.startAnimation(myAnim); 

When a button is pressed, the rotation must stop. Hence in my onClick(), I called clearAnimation().

objectImg.startAnimation(myAnim); 

My simple question is whether stopping the animation is the right thing to do. I assume clearAnimation() corresponds to loadAnimation(), but there is no stopAnimation() that corresponds to startAnimation().

Answer

CommonsWare picture CommonsWare · Oct 12, 2010

Use clearAnimation() to stop an animation. There is no loadAnimation() on View.