onAnimationEnd()的调用次数与AnimatorSet.start()的调用次数不同吗?

时间:2018-09-18 11:13:13

标签: android android-animation animatorset

我正在使用Animator循环播放动画。

AnimatorSet anim = new AnimatorSet();
private int countAnimation;

private void initViewRunAnimation() {
//init view
item = ...;
playAnimation(item);
}

private void playAnimation(View item) {
 anim = new AnimatorSet();
 anim.play(...);
anim.setTarget(item);
        anim.setInterpolator(new LinearInterpolator());
        anim.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                countAnimation--;
                if (countAnimation <= 0)
                    addImageAndRunAnimation();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        anim.start();
        countAnimation++;

} 

每次调用playAnimation都会创建一个新的AnimatorSet,并且onAnimationEnd的调用次数应与创建的AnimatorSet对象的次数相同。在Android 8中,它运作良好,但在Android 5.0.2中,当playAnimation的调用次数大于3时,onAnimationEnd的调用次数少于此次数,有时是1次,有时是2次,甚至是3次。 countAnimation始终大于0,因此无法播放循环。
我不知道为什么@@
请帮忙!

0 个答案:

没有答案