Android 12 Developer Preview is here! Try it out, and give us your feedback!

ValueAnimator

open class ValueAnimator : Animator, AnimationFrameCallback
kotlin.Any
   ↳ androidx.core.animation.Animator
   ↳ androidx.core.animation.ValueAnimator

This class provides a simple timing engine for running animations which calculate animated values and set them on target objects.

There is a single timing pulse that all animations use. It runs in a custom handler to ensure that property changes happen on the UI thread.

By default, ValueAnimator uses non-linear time interpolation, via the AccelerateDecelerateInterpolator class, which accelerates into and decelerates out of an animation. This behavior can be changed by calling ValueAnimator#setInterpolator(Interpolator).

Animators can be created from either code or resource files. Here is an example of a ValueAnimator resource file:

ValueAnimator also supports the use of a combination of PropertyValuesHolder and Keyframe resource tags to create a multi-step animation. Note that you can specify explicit fractional values (from 0 to 1) for each keyframe to determine when, in the overall duration, the animation should arrive at that value. Alternatively, you can leave the fractions off and the keyframes will be equally distributed within the total duration:

Summary

Constants
static Int

This value used used with the setRepeatCount(int) property to repeat the animation indefinitely.

static Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

static Int

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation reverses direction on every iteration.

Inherited constants
Public constructors

Creates a new ValueAnimator object.

Public methods
open static Boolean

Returns whether animators are currently enabled, system-wide.

open Unit

open ValueAnimator

open Unit
end()

open Float

Returns the current animation fraction, which is the elapsed/interpolated fraction used in the most recent frame update on the animation.

open Any

The most recent value calculated by this ValueAnimator when there is just one property being animated.

open Any?
getAnimatedValue(@NonNull propertyName: String)

The most recent value calculated by this ValueAnimator for propertyName.

open Long

Gets the current position of the animation in time, which is equal to the current time minus the time that the animation started.

open Long

Gets the length of the animation.

open static Long

The amount of time, in milliseconds, between each frame of the animation.

open Interpolator?

Returns the timing interpolator that this ValueAnimator uses.

open String

Returns the name of this animator for debugging purposes.

open Int

Defines how many times the animation should repeat.

open Int

Defines what this animation should do when it reaches the end.

open Long

The amount of time, in milliseconds, to delay starting the animation after start() is called.

open Long

open Array<PropertyValuesHolder!>

Returns the values that this ValueAnimator animates between.

open Boolean

open Boolean

open static ValueAnimator
ofArgb(@NonNull vararg values: Int)

Constructs and returns a ValueAnimator that animates between color values.

open static ValueAnimator
ofFloat(@NonNull vararg values: Float)

Constructs and returns a ValueAnimator that animates between float values.

open static ValueAnimator
ofInt(@NonNull vararg values: Int)

Constructs and returns a ValueAnimator that animates between int values.

open static ValueAnimator
ofObject(@NonNull evaluator: TypeEvaluator<Any!>, @NonNull vararg values: Any!)

Constructs and returns a ValueAnimator that animates between Object values.

open static ValueAnimator
ofPropertyValuesHolder(@NonNull vararg values: PropertyValuesHolder!)

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

open Unit

open Unit

open Unit

Plays the ValueAnimator in reverse.

open Unit