微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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。 有什么问题?

解决方法

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。