Android ValueAnimator在重复期间暂停 [英] Android ValueAnimator pauses during repeat

查看:458
本文介绍了Android ValueAnimator在重复期间暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用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();

//根据动画时间和开始/结束

invalidate();

}
})设置绘制位置。
mFigureAnimator.setRepeatCount(ValueAnimator.INFINITE);
mFigureAnimator.setRepeatMode(ValueAnimator.RESTART);
mFigureAnimator.start();


解决方案

对于动画,您可以将插值器配置为 LinearInterpolator :

  android:interpolator = @ android:anim / linear_interpolator 

对于Animator, LinearInterpolator 也对我有用,我有一个旋转动画器,执行360度旋转并重复无穷大:

 公共类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 degree){
this.mDegrees = degree;
//使视图无效,以便它可以重绘自身
invalidate();
}

}

这样可以解决我的问题您找不到其他解决方案,希望这对您有帮助,祝您好运。


So I'm using a ValueAnimator to animate a stick figure's limbs from one position to another, in an infinite loop, or at least until the animation is stopped. My problem is that when the animator repeats I have a slight pause as if the animation is lagging behind, but it only happens when the animation repeats. I have other animations that only happen once and those run perfectly smoothly, and they have just as much computation each time so I'm currently thinking that it's a problem with the ValueAnimator.

In the past I was able to find other people complaining about this problem, but I haven't been able to find anyone who has found a solution. Do you guys know if this is a real problem with the Android ValueAnimator? If so, do you know of any solutions? If not, do you guys have any ideas as to why this could be happening to me in just that one place in the animation? I'm really stuck on this one.

My code for the ValueAnimator setup is this:

    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();

解决方案

for Animation, you can configure the interpolator as LinearInterpolator in the animation file :

android:interpolator="@android:anim/linear_interpolator"

for Animator, LinearInterpolator also work for me, I had a rotate animator, do 360 degrees rotation and repeat infinite:

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();
    }

}

that way solved my problem, if you couldn't find another solution, hope this can help you, good luck.

这篇关于Android ValueAnimator在重复期间暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆