我想在一个 Drawable
(而不是一个 View
)上使用 ObjectAnimator
。
假设我有一个带有 Drawable
资源的 ImageView
:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:background="@color/myColor"
android:src="@drawable/myDrawable/>
我希望的是只有
myDrawable
被动画化,而不是例如在ImageView
上设置的背景。现在如果我在可绘制对象上应用
ObjectAnimator
,则不会发生任何事情:ImageView imageView = (ImageView) findViewById(R.id.imageView);
Drawable myDrawable = imageView.getDrawable();
ObjectAnimator animator = ObjectAnimator.ofFloat(myDrawable, "alpha", 1f, 0f);
animator.setDuration(1000);
animator.start();
为什么?
AnimationDrawable
不是ObjectAnimator
,它强制你必须有多个Drawable
作为动画帧。 - brescia123Button
和TextView
的复合可绘图上正常工作。 - brescia123