2017-02-17 50 views
0

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

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

正如我所说的背景颜色发生了变化,但第一次查看时冻结(仅第一次)长

我如何解决我的问题?感谢大家。

回答

0

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

你能发布更多的代码吗?