微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/android/311407.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐