Android ArgbEvaluator计算分数

时间:2017-09-22 05:11:44

标签: android android-animation

我在使用ArgbEvaluator对象时有点困难。 我想在特定的持续时间内将视图的颜色从一种颜色更改为另一种颜色。所以我编写这段代码,效果很好。

ValueAnimator animator = ValueAnimator.ofArgb(Color.RED,Color.BLUE);
    animator.setDuration(5000);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int color = (int) animation.getAnimatedValue();
            view.setBackgroundColor(color);
        }
    });
    animator.start();

但是我想用ArgbEvaluator来制作这样的动画。

public void setColor(fraction){
    int color = evaluator.evaluate(fraction,startColor,endColor);
    view.setBackgroundColor(color);
}

上面的setColor方法将被称为agian并且再次被称为特定持续时间(例如-5000ms)。 这是我的问题。 我不知道如何计算在特定持续时间内改变颜色的分数。 我想知道fraction的计算公式。谢谢。

0 个答案:

没有答案
相关问题