Android的objectAnimator动画布局的backgroundColor [英] Android objectAnimator animate backgroundColor of Layout
问题描述
我有一个问题。我想一个的LinearLayout
,使用 objectanimator
的动画背景颜色。维基,问题是,它的动画,但它确实对时间既不关心也不 valueFrom
和 valueTo
。
I have a problem. I want to animate the background color of a LinearLayout
, using objectanimator
.
The problem is that it animates, but it does neither care about duration nor valueFrom
and 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的我称之为是这样的:
In Java I call like this:
ObjectAnimator objAnim = (ObjectAnimator)AnimatorInflater.loadAnimator(getActivity(), R.animator.animator_bkg);
objAnim.setTarget(view);
objAnim.start();
请注意,当我动画布局的α,它将按预期工作。
这是(华硕变压器4.0.3)是Android的bug,还是我错过了什么?
Note that when I animate the alpha of the layout, it works as expected.
Is this an Android bug (4.0.3 on Asus Transformer), or I miss something?
推荐答案
我GOOGLE了一下。有一个答案。尝试使用TransitionDrawable。 <一href="http://developer.android.com/guide/topics/resources/drawable-resource.html#Transition">http://developer.android.com/guide/topics/resources/drawable-resource.html#Transition
I googled a bit. There is an answer. Try to use TransitionDrawable. http://developer.android.com/guide/topics/resources/drawable-resource.html#Transition
此外,有某处stackoverflow.com专用于相同的问题的一个话题。
Also, there is a topic somewhere on stackoverflow.com dedicated to the same problem.
ADDED code例如:
ADDED Code example:
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的objectAnimator动画布局的backgroundColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!