如何在没有调用Listener.onAnimationEnd的情况下停止ValueAnimator

L. *_*ter 3 android android-animation objectanimator

我在中添加了AnimatorListenerAdapter一个ValueAnimator,但我需要ValueAnimator在它运行时停止。

我尝试过ValueAnimator.cancel()ValueAnimator.stop(),它们都可以停止动画制作器,但是AnimatorListenerAdapter.onAnimationEnd()我不希望这样调用。

ValueAnimator.pause() 可以,但是只能在api 19以上,所以我不能使用它;

无论如何我还能做到吗?

小智 10

在某些情况下,标志的使用可能会导致问题。

您应该在调用取消方法之前使用 removeListener:

animator.removeAllListeners(); // Or animator.removeListener(your listener);
animator.cancel();
Run Code Online (Sandbox Code Playgroud)


Com*_*are 5

使用cancel()stop(),以及boolean某处的字段。将boolean作为一个标志,告诉onAnimationEnd()它是否不应该做其日常工作。默认booleantrue; false当您要阻止正常的动画结束处理时,将其翻转到。