Int*_*vix 4 animation android android-animation
因此,我使用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();
Run Code Online (Sandbox Code Playgroud)
对于Animation,您可以在动画文件中将插值器配置为LinearInterpolator:
android:interpolator="@android:anim/linear_interpolator"
Run Code Online (Sandbox Code Playgroud)
对于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();
}
}
Run Code Online (Sandbox Code Playgroud)
这样解决了我的问题,如果你找不到另一个解决方案,希望这可以帮助你,祝你好运.