问题描述
AnimatorSet animatorSet = new AnimatorSet();
ValueAnimator anim1 = ValueAnimator.ofFloat(0f,1f);
ValueAnimator anim2 = ValueAnimator.ofFloat(1f,0f);
~~~
animatorSet.play(anim1).after(anim2);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
Log.d("Testing","cancel");
}
}
animatorSet.start();
button.setonclickListener((v) -> {
animatorSet.cancel();
})
当 Button
被点击时,取消监听器运行良好。但是,不仅在 cancel()
版本 (API23
) 中调用 Marshmallow
。
有什么问题?
解决方法
尝试将您的 cancel()
方法修改为:
public void cancel() {
if (animatorSet != null) {
animatorSet.cancel();
}
if (next != null) {
next.cancel();
next = null;
}
}
它也适用于 API 23。如果没有,请分享您项目的更多代码以重建它并找到其他解决方案。