Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在已设置动画的颜色之间更改肋视图颜色_Android_Android Animation_Android Custom View - Fatal编程技术网

Android 在已设置动画的颜色之间更改肋视图颜色

Android 在已设置动画的颜色之间更改肋视图颜色,android,android-animation,android-custom-view,Android,Android Animation,Android Custom View,我有一个自定义视图,我画了一条弧来表示事件的进度,比如两个日期之间经过的时间。看起来是这样的: 随着时间的推移,我想在弧冷却器和红色之间改变弧的笔划颜色 我试过以下方法,但不起作用: remainingTimeProgress = (DonutProgress) rootView.findViewById(R.id.remainingTimeIndicator); Integer colorFrom = getResources().getColor(R.color.donut_finishe

我有一个自定义视图,我画了一条弧来表示事件的进度,比如两个日期之间经过的时间。看起来是这样的:

随着时间的推移,我想在弧冷却器和红色之间改变弧的笔划颜色

我试过以下方法,但不起作用:

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();
以下是我的自定义视图代码:

我该怎么做

更新

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

colorAnimation.setDuration(15000);
colorAnimation.setCurrentPlayTime(0);
它已经奏效了。但是,当我将播放时间动态设置为“经过的时间”时,它不会将颜色更改为当时应该的颜色

你知道有什么问题吗

更新

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

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

启动后调用设置当前播放时间: