具有恒定速度的Android ObjectAnimator
我使用ObjectAnimator将视图从0旋转到360度。但是旋转的速度不是恒定的。我需要一个恒定的速度,因为动画应该重复几次。速度的任何加速都会干扰动画的一致性。这是我的代码:具有恒定速度的Android ObjectAnimator,android,objectanimator,Android,Objectanimator,我使用ObjectAnimator将视图从0旋转到360度。但是旋转的速度不是恒定的。我需要一个恒定的速度,因为动画应该重复几次。速度的任何加速都会干扰动画的一致性。这是我的代码: ObjectAnimator animRotate = ObjectAnimator.ofFloat(ivLoader,"rotation", 0,360); animRotate.addListener(new Animator.AnimatorListener() { @Override
ObjectAnimator animRotate = ObjectAnimator.ofFloat(ivLoader,"rotation", 0,360);
animRotate.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
animRotate.start();
}
});
animRotate.start();
签出类,ValueAnimator
(ObjectAnimator
正在扩展它)的默认类是:
它将在“启动阶段”加速,并在结束时减速。您需要线性插值,以便:
ObjectAnimator animRotate = ...
animRotate.setInterpolator(new LinearInterpolator());
animRotate.addListener(... // rest of code
但请考虑用< /P>替换<代码>
animRotate.setRepeatMode(ValueAnimator.INFINITE);
还有setRepeatCount
方法签出类,ValueAnimator
(ObjectAnimator
正在扩展它)的默认类是:
它将在“启动阶段”加速,并在结束时减速。您需要线性插值,以便:
ObjectAnimator animRotate = ...
animRotate.setInterpolator(new LinearInterpolator());
animRotate.addListener(... // rest of code
但请考虑用< /P>替换<代码>
animRotate.setRepeatMode(ValueAnimator.INFINITE);
还有setRepeatCount
方法