Android: How to stop the endless animation applied to ImageView?

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

android:repeatCount="infinite" 

In onCreate (), load the animation and run it.

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

When the button is pressed, rotation should stop. Therefore, in my onClick (), I called clearAnimation ().

 objectImg.startAnimation(myAnim); 

My simple question is whether to stop the animation. I suppose clearAnimation () corresponds to loadAnimation (), but there is no stopAnimation () which corresponds to startAnimation ().

+25
source share
2 answers

You can also call anim.cancel(); , but you should also call anim.reset(); right after him. Then, when you want to start it again, just call startAnimation in the view.

+26
source

Use clearAnimation() to stop the animation. No loadAnimation() on View .

+54
source

All Articles