Repeat AnimatorSet

后端 未结 7 1590
被撕碎了的回忆
被撕碎了的回忆 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:17

    So, none of the above options are appropriate.

    If you use:

      @Override
      public void onAnimationEnd(Animator animation) {
        if (!mCanceled) {
          animation.start();
        }
      }
    

    you will end up getting stackOverFlow exception sometimes.

    The best thing is to do something like:

    Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    while (true && getActivity() != null) {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                set3.start();
                            }
                        });
                        SystemClock.sleep(1200);
                    }
                }
            });
            t.start();
    

提交回复
热议问题