Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeat AnimatorSet

Tags:

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?

like image 897
sockeqwe Avatar asked Jul 12 '13 19:07

sockeqwe


People also ask

What is AnimatorSet Android?

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.

How do I set up animator on Android?

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.


2 Answers

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.

like image 198
wkhatch Avatar answered Sep 18 '22 08:09

wkhatch


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.

like image 34
daus Avatar answered Sep 18 '22 08:09

daus