ObjectAnimator
ObjectAnimator
是 ValueAnimator
的子类,具有将计算值设置为 target
View
属性的附加功能。
就像在 ValueAnimator
中一样,有两种方法可以创建 ObjectAnimator
:
(示例代码在 250ms
中将 View
的 alpha
从 0.4f
激活到 0.2f
)
- 来自
xml
(把它放在/res/animator
)
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="250"
android:propertyName="alpha"
android:valueFrom="0.4"
android:valueTo="0.2"
android:valueType="floatType"/>
ObjectAnimator animator = (ObjectAnimator) AnimatorInflater.loadAnimator(context,
R.animator.example_animator);
animator.setTarget(exampleView);
// set all the animation-related stuff you want (interpolator etc.)
animator.start();
- 来自代码:
ObjectAnimator animator = ObjectAnimator.ofFloat(exampleView, View.ALPHA, 0.4f, 0.2f);
animator.setDuration(250);
// set all the animation-related stuff you want (interpolator etc.)
animator.start();