views:

89

answers:

2

Hi,

I have an ImageView on which I have applied 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 doubt is whether it's the right thing to do, to stop the animation? I assume clearAnimation() is to loadAnimation(), but there is no stopAnimation() corresponds to startAnimation().

-Kiki

+2  A: 

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

CommonsWare
Ok, thanks. So only startAnimation() and clearAnimation() are pplicable to views.
kiki
+1  A: 

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

John J Smith
ok, i will check this out as well.
kiki