Android 无法更改视图中的背景

Android 无法更改视图中的背景,android,android-animation,Android,Android Animation,我正在尝试更改视图的背景色。我写了一些代码,我可以用动画改变颜色,但第一次我的视图在颜色改变之前是冻结的。这是我的密码 private void changeBackgroundColorWithAnimation(int duration, final View view, int startColor, int endColor) { ValueAnimator anim = new ValueAnimator(); anim.setIntValues(startColor,

我正在尝试更改视图的背景色。我写了一些代码,我可以用动画改变颜色,但第一次我的视图在颜色改变之前是冻结的。这是我的密码

private void changeBackgroundColorWithAnimation(int duration, final View view, int startColor, int endColor) {
    ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(startColor, endColor);
    anim.setEvaluator(new ArgbEvaluator());
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            view.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());

        }
    });

    anim.setDuration(duration);
    anim.start();
}
我这样调用我的函数:

changeBackgroundColorWithAnimation(300, TransferFragmentNewVersion.rootLayout, 
    Color.parseColor("#E6000000"), Color.WHITE);
正如我所说的,背景颜色已经改变了,但是第一次视图是冻结的(只有第一次)


我怎样才能解决我的问题?谢谢大家。

为什么不发送视图的初始颜色作为起始颜色? 您可以用
TransferFragmentNewVersion.rootLayout.getSolidColor()
替换
Color.parseColor(“#e600000”)

你能发布更多的代码吗