【问题标题】:Change costum View color between colors animated在动画颜色之间更改自定义视图颜色
【发布时间】:2015-06-25 07:09:39
【问题描述】:

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

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

我尝试了以下方法,但它不起作用:

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

【问题讨论】:

    标签: android android-animation android-custom-view


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      相关资源
      最近更新 更多