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

时间:2016-01-18 05:02:54

标签: android android-animation objectanimator

我在AnimatorListenerAdapter中添加ValueAnimator,但我需要在ValueAnimator运行的时候停止它。

我尝试了ValueAnimator.cancel()ValueAnimator.stop(),他们都可以停止动画师,但AnimatorListenerAdapter.onAnimationEnd()被调用,这是我不想要的。

ValueAnimator.pause()有效,但它仅高于api 19,所以我无法使用它;

我还能做到这一点吗?

2 个答案:

答案 0 :(得分:7)

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

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

animator.removeAllListeners(); // Or animator.removeListener(your listener);
animator.cancel();

答案 1 :(得分:4)

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