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().
clearAnimation() To stop the animation that going on in a loop.
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
ObjectAnimator is a Subclass of ValueAnimator, which allows us to set a target object and object property to animate. It is an easy way to change the properties of a view with a specified duration. We can provide the end position and duration of the animation.
Drawable animation lets you load a series of Drawable resources one after another to create an animation. This is a traditional animation in the sense that it is created with a sequence of different images, played in order, like a roll of film. The AnimationDrawable class is the basis for Drawable animations.
Use clearAnimation()
to stop an animation. There is no loadAnimation()
on View
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With