Android AnimatorSet.cancel() 在 Marshmallow 版本设备上不起作用

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。 有什么问题?

jiajia2xm 回答:Android AnimatorSet.cancel() 在 Marshmallow 版本设备上不起作用

尝试将您的 cancel() 方法修改为:

public void cancel() {
  if (animatorSet != null) {
    animatorSet.cancel();
  }
  if (next != null) {
    next.cancel();
    next = null;
  }
}

它也适用于 API 23。如果没有,请分享您项目的更多代码以重建它并找到其他解决方案。

本文链接:https://www.f2er.com/2097.html

大家都在问