简体   繁体   English

Android动画:如何在运行时更改动画速度

[英]Android animation: How to change animation speed during Runtime

Im using Property Animation to animate a swinging pendulum (single image). 我正在使用属性动画为摆动的钟摆(单个图像)设置动画。 There's a button with click event which would increase the speed of the pendulum. 有一个带有单击事件的按钮,它将增加摆锤的速度。 Im unsure how I could achieve this. 我不确定如何实现这一目标。 I understand that the duration of the animation is set by the call setDuration() which has an effect on the speed. 我知道动画的持续时间是由setDuration()设置的,它会影响速度。 Should setDuration() be used to change the speed of the animation during runtime? 应该使用setDuration()在运行时更改动画的速度吗? eg. 例如。

public void onAnimationUpdate(ValueAnimator animation) {
            animator.setDuration(speed);
}

Where the property 'speed' is changed via the button's click event. 通过按钮的click事件更改“速度”属性的位置。

Am I on the right track or going off at a different tangent entirely? 我是在正确的轨道上还是在完全不同的切线处出发?

Note: The pendulum should not be restarted. 注意:摆锤不应该重新启动。 It should continue to swing with the updated speed when the button is clicked. 单击按钮后,它应继续以更新的速度摆动。

detect the min or max value of animation in update listener, and then use anim.cancel(); 在更新侦听器中检测动画的最小值或最大值,然后使用anim.cancel(); anim.setDuration(speed); anim.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM