ObjectAnimator
is a subclass of ValueAnimator
with the added ability to set the calculated value to the property of a target
View
.
Just like in the ValueAnimator
, there are two ways you can create the ObjectAnimator
:
(the example code animates an alpha
of a View
from 0.4f
to 0.2f
in 250ms
)
xml
(put it in the /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();