我用ObjectAnimator将我的视野从0度旋转到360度。但是旋转的速度不是恒定的。我需要一个恒定的速度,因为动画应该重复几次。任何速度的加速都会干扰动画的一致性。这是我的密码:
ObjectAnimator animRotate = ObjectAnimator.ofFloat(ivLoader,"rotation", 0,360);
animRotate.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
animRotate.start();
}
});
animRotate.start();发布于 2019-08-14 07:36:04
查看插补器类,ValueAnimator的默认类(ObjectAnimator正在扩展它)是:
private static final TimeInterpolator sDefaultInterpolator =
new AccelerateDecelerateInterpolator();它将在“开始阶段”加速,并最终退出。你想要线性插值,所以:
ObjectAnimator animRotate = ...
animRotate.setInterpolator(new LinearInterpolator());
animRotate.addListener(... // rest of code但是请考虑用以下方式替换AnimatorListener
animRotate.setRepeatMode(ValueAnimator.INFINITE);还有setRepeatCount方法
https://stackoverflow.com/questions/57490027
复制相似问题