因此,我正在使用 ValueAnimator 以无限循环或至少直到动画停止为止,为简笔画的四肢从一个位置设置动画到另一个位置。我的问题是,当动画师重复时,我有轻微的停顿,好像动画滞后了,但它只发生在动画重复时。我还有其他只发生一次并且运行非常流畅的动画,它们每次都有同样多的计算,所以我目前认为这是 ValueAnimator 的问题。
过去我能找到其他人提示这个问题,但我没能找到找到解决方案的人。你们知道这是否是 Android ValueAnimator 的真正问题?如果是这样,您知道任何解决方案吗?如果不是,你们有什么想法,为什么我会在动画中的那个地方发生这种情况?我真的坚持这个。
我的 ValueAnimator 设置代码是这样的:
mFigureAnimator = ValueAnimator.ofFloat(0f, 1f);
mFigureAnimator.setInterpolator(new LinearInterpolator());
mFigureAnimator.setDuration(1000);
mFigureAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
Float delta = (Float)animation.getAnimatedValue();
// Set the drawn locations based on the animated time and the start/end
invalidate();
}
});
mFigureAnimator.setRepeatCount(ValueAnimator.INFINITE);
mFigureAnimator.setRepeatMode(ValueAnimator.RESTART);
mFigureAnimator.start();
最佳答案
对于Animation,你可以在动画文件中配置插值器为LinearInterpolator:
android:interpolator="@android:anim/linear_interpolator"
对于 Animator,LinearInterpolator 也适合我,我有一个旋转动画师,做 360 度旋转并无限重复:
public class RotateAnimator {
private float mDegrees;
private ObjectAnimator mAnim;
private RotateAnimator() {
mAnim = ObjectAnimator.ofFloat(this, "degrees", 360);
mAnim.setInterpolator(new LinearInterpolator());
mAnim.setRepeatCount(ValueAnimator.INFINITE);
mAnim.setRepeatMode(ValueAnimator.INFINITE);
mAnim.setEvaluator(new FloatEvaluator());
mAnim.setDuration(2000);
mAnim.start();
}
public float getDegrees() {
return mDegrees;
}
public void setDegrees(float degrees) {
this.mDegrees = degrees;
// invalidate the view so it can redraw itself
invalidate();
}
}
这样解决了我的问题,如果您找不到其他解决方案,希望这对您有所帮助,祝您好运。
关于Android ValueAnimator 在重复期间暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19938394/