在动画颜色之间更改自定义视图颜色

Change costum View color between colors animated

我有一个自定义视图,我在其中绘制了一条弧线,表示事件的进展情况,例如两个日期之间经过的时间。它看起来像这样:

我想随着时间的推移更改我的弧形冷却器和红色之间的弧线的描边颜色。

我试过以下但没用:

remainingTimeProgress = (DonutProgress) rootView.findViewById(R.id.remainingTimeIndicator);
Integer colorFrom = getResources().getColor(R.color.donut_finished_color);
Integer colorTo = getResources().getColor(R.color.Red);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(currentTimeLength);
long passedTime = Calendar.getInstance().getTime().getTime() - currentDate.getTime();
colorAnimation.setCurrentPlayTime(passedTime);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

    @Override
    public void onAnimationUpdate(final ValueAnimator animator) {

        activity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Integer colorValue = (Integer) animator.getAnimatedValue();
                remainingTimeProgress.setFinishedStrokeColor(colorValue);
            }
        });
    }

});
colorAnimation.start();

这是我的自定义视图代码:http://pastebin.com/ERyLiczg

我该怎么做?

更新

我尝试了一些动画时间的硬编码值,例如:

colorAnimation.setDuration(15000);
colorAnimation.setCurrentPlayTime(0);

它奏效了。但是当我动态地将播放时间设置为过去的时间时,它不会将颜色更改为当时应该的颜色。

你知道问题出在哪里吗?

更新

启动后设置当前播放时间解决了问题。

colorAnimation.start();
colorAnimation.setCurrentPlayTime(passedTime);

开始后调用设置当前播放时间:

colorAnimation.start();
colorAnimation.setCurrentPlayTime(passedTime);