Android ObjectAnimation only started once

半世苍凉 提交于 2019-12-05 13:52:45

The second time you will try to animate from 360.0f to 360.0f. Change your call to ofFloat() to:

ObjectAnimator.ofFloat(v, "rotationY", 0.0f, 360.0f)

To elaborate on Romain's answer, the result of the single-value factory constructor is animation that will run from whatever the current value is to the value specified in the parameters. In your case, the object had a value of 0 to begin with an animated (the first time) to a value of 360. The second time it ran, it animated from the current value (360) to the specified value (360). Not much of an animation.

The fix is as above: hard-code both the start and end values for the animator. Alternatively, you can reset the value back to 0 when the animation finishes by implementing the AnimatorListener.onAnimationEnd method and resetting it when the animation finishes:

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            v.setRotationY(0);
        }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!