Android objectAnimator动画背景颜色布局

我有个问题.我想使用objectanimator为LinearLayout的背景颜色设置动画.问题是它动画,但它既不关心持续时间,也不关心valueFrom和valueto.

这是我的xml文件

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="2000"
android:propertyName="backgroundColor"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueFrom="#FF0000"
android:valueto="#000000" />

在Java中,我称之为:

ObjectAnimator objAnim = (ObjectAnimator)AnimatorInflater.loadAnimator(getActivity(),R.animator.animator_bkg);
    objAnim.setTarget(view);
    objAnim.start();

请注意,当我对布局的alpha进行动画处理时,它的工作原理如预期.这是Android的错误(4.0.3在华硕变压器),还是我错过了什么?

解决方法

我google了一下有答案尝试使用TransitionDrawable. http://developer.android.com/guide/topics/resources/drawable-resource.html#Transition

而且,stackoverflow.com上还有一个专门针对相同问题的主题.

ADDED代码示例:

Button btn = (Button)this.findViewById(R.id.btn1);
    //Let's change background's color from blue to red.
    ColorDrawable[] color = {new ColorDrawable(Color.BLUE),new ColorDrawable(Color.RED)};
    TransitionDrawable trans = new TransitionDrawable(color);
    //This will work also on old devices. The latest API says you have to use setBackground instead.
    btn.setBackgroundDrawable(trans);
    trans.startTransition(5000);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...