Property Animation is a powerful animation framework introduced in Android 3.0 (API 11). Unlike the older View Animation (tween animation) system, property animation actually changes the properties of the target object, not just its rendered appearance.

Why Property Animation?

The legacy View Animation system (android.view.animation.Animation) had a fundamental flaw: it only changed where a View was drawn, not its actual properties. For example, if you animated a Button to move to the right side of the screen, clicking the original position would still trigger the button — because the View’s clickable region never moved. Property animation solves this by directly modifying the actual property values (like x, y, alpha) of the target object.

Core APIs

The core classes reside in the android.animation package:

ObjectAnimator

The most commonly used class. It directly animates a named property of a target object:

1
2
3
ObjectAnimator anim = ObjectAnimator.ofFloat(foo, "alpha", 0f, 1f);
anim.setDuration(1000);
anim.start();

ValueAnimator

A lower-level class that animates values without applying them to any specific object. You must provide an update listener to apply each frame’s value:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        float value = (float) animation.getAnimatedValue();
        view.setAlpha(value);
    }
});
animator.setDuration(300);
animator.start();

AnimatorSet

Used to orchestrate multiple animations — playing them together, sequentially, or with delays:

1
2
3
4
AnimatorSet set = new AnimatorSet();
set.play(anim1).before(anim2);
set.play(anim2).with(anim3);
set.start();

Configurable Properties

PropertyDescriptionDefault
DurationHow long the animation runs300ms
TimeInterpolatorControls the rate of changeAccelerateDecelerateInterpolator
RepeatCountNumber of times to repeat0 (no repeat)
RepeatModeRESTART or REVERSERESTART
StartDelayDelay before animation starts0
FrameRefreshDelayFrame refresh interval (rarely changed)10ms

Note: The actual frame rate depends not only on the configured delay but also on system performance and resource usage.

Interpolators

Android provides several built-in interpolators:

  • LinearInterpolator — constant speed
  • AccelerateDecelerateInterpolator — accelerate then decelerate
  • AccelerateInterpolator — accelerate only
  • DecelerateInterpolator — decelerate only
  • BounceInterpolator — bounce effect at the end
  • AnticipateOvershootInterpolator — pull back then overshoot the target

You can also implement TimeInterpolator to create custom interpolators.

ViewPropertyAnimator

For simple multi-property view animations, ViewPropertyAnimator provides a fluent API:

1
2
3
4
5
view.animate()
    .alpha(0.5f)
    .translationX(200f)
    .setDuration(1000)
    .start();

Animation Listeners

Use AnimatorListener or the convenience class AnimatorListenerAdapter to react to animation events:

1
2
3
4
5
6
anim.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        // Handle post-animation logic
    }
});

References