Repeat AnimatorSet

后端 未结 7 1600
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 09:19

Is there a simple way to repeat a Android AnimatorSet (infinite)? Can I set a AnimationListener and restart the AnimatorSet by calling

7条回答
  •  忘了有多久
    2021-02-05 10:00

    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.

提交回复
热议问题