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
) 中调用。有什么问题?