Is there a simple way to repeat a Android AnimatorSet
(infinite)? Can I set a AnimationListener
and restart the AnimatorSet
by calling start()
again?
My AnimatorSet
contains two animations that are played sequentially.
So if I set the repeat mode of both single animation to repeat, than the first will be repeated while the second runs, right?
android.animation.AnimatorSet. This class plays a set of Animator objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.
Navigate to the app > res > Right-Click on res >> New >> Directory >> Name your directory as “anim”. Inside this directory, we will create our animations. For creating a new anim right click on the anim directory >> Animation Resource file and give the name to your file.
set it's child object animators' repeat mode and count;
objectAnimator.setRepeatCount(ObjectAnimator.INFINITE);
objectAnimator.setRepeatMode(ObjectAnimator.RESTART/REVERSE...);
This won't be able to be stopped, or cancelled, however, due to yet another bug.
clearly, I'm not a fan of the myriad ways in which you can animate things in Android, and have them all fail you in one way or the other. Hope this helps somebody else.
There is an answer for the first two questions
Is there a simple way to repeat a Android AnimatorSet (infinite)? Can I set a AnimationListener and restart the animatorSet by calling start() again?
Yes, there is:
mAnimationSet.addListener(new AnimatorListenerAdapter() {
private boolean mCanceled;
@Override
public void onAnimationStart(Animator animation) {
mCanceled = false;
}
@Override
public void onAnimationCancel(Animator animation) {
mCanceled = true;
}
@Override
public void onAnimationEnd(Animator animation) {
if (!mCanceled) {
animation.start();
}
}
});
mAnimationSet.start();
The answer for the third question, is no. The first animation will be repeated and after all repetitions the succeeding animation will be started.
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