Google is committed to advancing racial equity for Black communities. See how.

androidx.animation

Classes

AnimatedFloat

This class inherits most of the functionality from BaseAnimatedValue.

AnimatedValue

AnimatedValue is an animatable value holder.

AnimationBuilder

Animation builder for creating an animation that animates a value of type T.

AnimationVector

AnimationVector class that is the base class of AnimationVector1D, AnimationVector2D, AnimationVector3D and AnimationVector4D.

AnimationVector1D

This class defines a 1D vector.

AnimationVector2D

This class defines a 2D vector that contains two Float values for the two dimensions.

AnimationVector3D

This class defines a 3D vector that contains three Float value fields for the three dimensions.

AnimationVector4D

This class defines a 4D vector that contains four Float fields for its four dimensions.

BaseAnimatedValue

This is the base class for AnimatedValue.

BaseAnimationClock

Base implementation for the AnimationClockObservable that handles the subscribing and unsubscribing logic that would be common for all custom animation clocks.

CubicBezierEasing

A cubic polynomial easing.

DecayAnimation

Fixed Decay animation wraps around a FloatDecayAnimationSpec and assumes its starting value and velocity never change throughout the animation.

DefaultAnimationClock

Default Choreographer based clock that pushes a new frame to all subscribers on each Choreographer tick, until all subscribers have unsubscribed.

DurationBasedAnimationBuilder

Base class for an AnimationBuilder to create animations based on a fixed duration.

ExponentialDecay

This is a decay animation where the friction/deceleration is always proportional to the velocity.

FloatPropKey

Built-in property key for Float properties.

FloatSpringSpec

FloatSpringSpec animation uses a spring animation to animate a Float value.

FloatTweenSpec

FloatTweenSpec animates a Float value from any start value to any end value using a provided easing function.

IntPropKey

Built-in property key for Int properties.

KeyframesBuilder

KeyframesBuilder creates a KeyframesSpec animation.

KeyframesSpec

KeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.

ManualAnimationClock

A custom clock whose frame time can be manually updated via mutating clockTimeMillis.

PhysicsBuilder

PhysicsBuilder takes in the configuration of a spring as its constructor parameters.

RepeatableBuilder

Used for creating repeated animations where each iteration is defined by one of the duration based animations like TweenBuilder or KeyframesBuilder.

RepeatableSpec

This animation takes another DurationBasedAnimationSpec as a parameter and plays it iterationCount times.

SnapBuilder

Builds Snap animation for immediately switching the animating value to the end value.

SnapSpec

SnapSpec immediately snaps the animating value to the end value.

SpringSpec

SpringSpec uses spring animations to animate (each dimension of) AnimationVectors.

TargetAnimation

TargetAnimation class defines how to animate to a given target value.

TargetBasedAnimation

This is a convenient animation wrapper class that works for all target based animations, i.

TransitionAnimation

TransitionAnimation is the underlying animation used in androidx.ui.animation.Transition for animating from one set of property values (i.

TransitionDefinition

TransitionDefinition contains all the animation related configurations that will be used in a state-based transition.

TransitionSpec

Static specification for the transition from one state to another.

TweenBuilder

TweenBuilder builds a tween animation that animates from start to end value, based on an easing curve within the given duration.

TweenSpec

TweenSpec animates a AnimationVector value by interpolating the start and end value, in the given duration using the given easing curve.

Type-aliases

Easing

Easing is a way to adjust an animation’s fraction.

OnAnimationEnd

Typealias for lambda that will be invoked when fling animation ends.

Annotations

InternalAnimationApi

Enums

AnimationEndReason

Possible reasons with which DynamicTargetAnimation can finish

InterruptionHandling

Top-level constants summary

const Long

The default duration used in AnimationSpecs.

const Int

Used as a iterations count for RepeatableBuilder to create an infinity repeating animation.

Top-level functions summary

AnimatedFloat
AnimatedFloat(initVal: Float, clock: AnimationClockObservable, visibilityThreshold: Float = Spring.DefaultDisplacementThreshold)

Factory method for creating an AnimatedFloat object, and initialize the value field to initVal.

AnimatedValue<T, V>
AnimatedValue(initVal: T, typeConverter: TwoWayConverter<T, V>, clock: AnimationClockObservable, visibilityThreshold: V = typeConverter .convertToVector(initVal) .newInstanceOfValue(Spring.DefaultDisplacementThreshold))

Factory method for creating an AnimatedValue object, and initialize the value field to initVal.

AnimatedValue<V, V>
AnimatedVector(initVal: V, clock: AnimationClockObservable, visibilityThreshold: V = initVal.newInstanceOfValue(Spring.DefaultDisplacementThreshold))

Factory method for creating an AnimatedVector object, and initialize the value field to initVal.

AnimationVector1D

Factory method to create an AnimationVector1D

AnimationVector2D

Factory method to create an AnimationVector2D

AnimationVector3D
AnimationVector(v1: Float, v2: Float, v3: Float)

Factory method to create an AnimationVector3D

AnimationVector4D
AnimationVector(v1: Float, v2: Float, v3: Float, v4: Float)

Factory method to create an AnimationVector4D

TwoWayConverter<T, V>
TwoWayConverter(convertToVector: (T) -> V, convertFromVector: (V) -> T)

Factory method to create a TwoWayConverter that converts a type T from and to an AnimationVector type.

Long
estimateAnimationDurationMillis(stiffness: Float, dampingRatio: Float, initialVelocity: Float, initialDisplacement: Float, delta: Float)

Returns the estimated time that the spring will last be at delta

Long
estimateAnimationDurationMillis(stiffness: Double, dampingRatio: Double, initialVelocity: Double, initialDisplacement: Double, delta: Double)

Returns the estimated time that the spring will last be at delta

Long
estimateAnimationDurationMillis(springConstant: Double, dampingCoefficient: Double, mass: Double, initialVelocity: Double, initialDisplacement: Double, delta: Double)

Returns the estimated time that the spring will last be at delta

TransitionDefinition<T>

Creates a TransitionDefinition using the init function to initialize it.

Top-level properties summary

CubicBezierEasing

Elements exiting a screen use acceleration easing, where they start at rest and end at peak velocity.

CubicBezierEasing

Elements that begin and end at rest use this standard easing.

TwoWayConverter<Float, AnimationVector1D>

A TwoWayConverter that converts Float from and to AnimationVector1D

TwoWayConverter<Int, AnimationVector1D>

A TwoWayConverter that converts Int from and to AnimationVector1D

Easing

It returns fraction unmodified.

CubicBezierEasing

Incoming elements are animated using deceleration easing, which starts a transition at peak velocity (the fastest point of an element’s movement) and ends at rest.

Extension functions summary

For AnimationSpec
TargetBasedAnimation<V, V>
AnimationSpec<V>.createAnimation(startValue: V, endValue: V, startVelocity: V)

Creates a TargetBasedAnimation from a given AnimationSpec of AnimationVector type.

TargetBasedAnimation<T, V>
AnimationSpec<V>.createAnimation(startValue: T, endValue: T, startVelocityVector: V, converter: TwoWayConverter<T, V>)

Creates a TargetBasedAnimation from a given AnimationSpec of AnimationVector type.

For FloatDecayAnimationSpec
Animation<Float, AnimationVector1D>
FloatDecayAnimationSpec.createAnimation(startValue: Float, startVelocity: Float = 0f)

Creates a Animation (with a fixed start value and start velocity) that decays over time based on the given FloatDecayAnimationSpec.

For TransitionDefinition
TransitionAnimation<T>

Creates a transition animation using the transition definition and the given clock.

For AnimatedFloat
Unit
AnimatedFloat.fling(startVelocity: Float, decay: FloatDecayAnimationSpec = ExponentialDecay(), onEnd: OnAnimationEnd? = null)

Starts a fling animation with the specified starting velocity.

Unit
AnimatedFloat.fling(startVelocity: Float, decay: FloatDecayAnimationSpec = ExponentialDecay(), adjustTarget: (Float) -> TargetAnimation?, onEnd: OnAnimationEnd? = null)

Starts a fling animation with the specified starting velocity.

For Animation
T
Animation<T, V>.getVelocity(playTime: Long)

Returns the velocity of the animation at the given play time.

For FloatAnimationSpec
AnimationSpec<V>

Create an AnimationSpec that animates AnimationVector from a FloatAnimationSpec.

Top-level constants

DefaultDuration

const val DefaultDuration: Long

The default duration used in AnimationSpecs.

Value: 300L

Infinite

const val Infinite: Int

Used as a iterations count for RepeatableBuilder to create an infinity repeating animation.

Value: Int.MAX_VALUE

Top-level functions

AnimatedFloat

fun AnimatedFloat(
    initVal: Float,
    clock: AnimationClockObservable,
    visibilityThreshold: Float = Spring.DefaultDisplacementThreshold
): AnimatedFloat

Factory method for creating an AnimatedFloat object, and initialize the value field to initVal.

Parameters
initVal: Float Initial value to initialize the animation to.
clock: AnimationClockObservable The animation clock used to drive the animation.
visibilityThreshold: Float = Spring.DefaultDisplacementThreshold Threshold at which the animation may round off to its target value.

AnimatedValue

fun <T, V : AnimationVector> AnimatedValue(
    initVal: T,
    typeConverter: TwoWayConverter<T, V>,
    clock: AnimationClockObservable,
    visibilityThreshold: V = typeConverter .convertToVector(initVal) .newInstanceOfValue(Spring.DefaultDisplacementThreshold)
): AnimatedValue<T, V>

Factory method for creating an AnimatedValue object, and initialize the value field to initVal.

Parameters
initVal: T Initial value to initialize the animation to.
typeConverter: TwoWayConverter<T, V> Converter for converting value type T to AnimationVector, and vice versa
clock: AnimationClockObservable The animation clock used to drive the animation.

AnimatedVector

fun <V : AnimationVector> AnimatedVector(
    initVal: V,
    clock: AnimationClockObservable,
    visibilityThreshold: V = initVal.newInstanceOfValue(Spring.DefaultDisplacementThreshold)
): AnimatedValue<V, V>

Factory method for creating an AnimatedVector object, and initialize the value field to initVal.

Parameters
initVal: V Initial value to initialize the animation to.
clock: AnimationClockObservable The animation clock used to drive the animation.

AnimationVector

fun AnimationVector(v1: Float): AnimationVector1D

Factory method to create an AnimationVector1D

Parameters
v1: Float value to set on the value field of AnimationVector1D

AnimationVector

fun AnimationVector(
    v1: Float,
    v2: Float
): AnimationVector2D

Factory method to create an AnimationVector2D

Parameters
v1: Float value to set on the first dimension
v2: Float value to set on the second dimension

AnimationVector

fun AnimationVector(
    v1: Float,
    v2: Float,
    v3: Float
): AnimationVector3D

Factory method to create an AnimationVector3D

Parameters
v1: Float value to set on the first dimension
v2: Float value to set on the second dimension
v3: Float value to set on the third dimension

AnimationVector

fun AnimationVector(
    v1: Float,
    v2: Float,
    v3: Float,
    v4: Float
): AnimationVector4D

Factory method to create an AnimationVector4D

Parameters
v1: Float value to set on the first dimension
v2: Float value to set on the second dimension
v3: Float value to set on the third dimension
v4: Float value to set on the fourth dimension

TwoWayConverter

fun <T, V : AnimationVector> TwoWayConverter(
    convertToVector: (T) -> V,
    convertFromVector: (V) -> T
): TwoWayConverter<T, V>

Factory method to create a TwoWayConverter that converts a type T from and to an AnimationVector type.

Parameters
convertToVector: (T) -> V converts from type T to AnimationVector
convertFromVector: (V) -> T converts from AnimatedVector to type T

estimateAnimationDurationMillis

fun estimateAnimationDurationMillis(
    stiffness: Float,
    dampingRatio: Float,
    initialVelocity: Float,
    initialDisplacement: Float,
    delta: Float
): Long

Returns the estimated time that the spring will last be at delta

estimateAnimationDurationMillis

fun estimateAnimationDurationMillis(
    stiffness: Double,
    dampingRatio: Double,
    initialVelocity: Double,
    initialDisplacement: Double,
    delta: Double
): Long

Returns the estimated time that the spring will last be at delta

estimateAnimationDurationMillis

fun estimateAnimationDurationMillis(
    springConstant: Double,
    dampingCoefficient: Double,
    mass: Double,
    initialVelocity: Double,
    initialDisplacement: Double,
    delta: Double
): Long

Returns the estimated time that the spring will last be at delta

transitionDefinition

fun <T> transitionDefinition(init: TransitionDefinition<T>.() -> Unit): TransitionDefinition<T>

Creates a TransitionDefinition using the init function to initialize it.

Parameters
init: TransitionDefinition<T>.() -> Unit Initialization function for the TransitionDefinition

Top-level properties

FastOutLinearInEasing

val FastOutLinearInEasing: CubicBezierEasing

Elements exiting a screen use acceleration easing, where they start at rest and end at peak velocity.

This is equivalent to the Android FastOutLinearInInterpolator

FastOutSlowInEasing

val FastOutSlowInEasing: CubicBezierEasing

Elements that begin and end at rest use this standard easing. They speed up quickly and slow down gradually, in order to emphasize the end of the transition.

Standard easing puts subtle attention at the end of an animation, by giving more time to deceleration than acceleration. It is the most common form of easing.

This is equivalent to the Android FastOutSlowInInterpolator

FloatToVectorConverter

val FloatToVectorConverter: TwoWayConverter<Float, AnimationVector1D>

A TwoWayConverter that converts Float from and to AnimationVector1D

IntToVectorConverter

val IntToVectorConverter: TwoWayConverter<Int, AnimationVector1D>

A TwoWayConverter that converts Int from and to AnimationVector1D

LinearEasing

val LinearEasing: Easing

It returns fraction unmodified. This is useful as a default value for cases where a Easing is required but no actual easing is desired.

LinearOutSlowInEasing

val LinearOutSlowInEasing: CubicBezierEasing

Incoming elements are animated using deceleration easing, which starts a transition at peak velocity (the fastest point of an element’s movement) and ends at rest.

This is equivalent to the Android LinearOutSlowInInterpolator

Extension functions

createAnimation

fun <V : AnimationVector> AnimationSpec<V>.createAnimation(
    startValue: V,
    endValue: V,
    startVelocity: V
): TargetBasedAnimation<V, V>

Creates a TargetBasedAnimation from a given AnimationSpec of AnimationVector type. This convenient method is intended for when the value being animated (i.e. start value, end value, etc) is of AnimationVector type.

Parameters
startValue: V the value that the animation will start from
endValue: V the value that the animation will end at
startVelocity: V the initial velocity to start the animation at

createAnimation

fun <T, V : AnimationVector> AnimationSpec<V>.createAnimation(
    startValue: T,
    endValue: T,
    startVelocityVector: V,
    converter: TwoWayConverter<T, V>
): TargetBasedAnimation<T, V>

Creates a TargetBasedAnimation from a given AnimationSpec of AnimationVector type.

Parameters
startValue: T the value that the animation will start from
endValue: T the value that the animation will end at
startVelocityVector: V the initial velocity (in the form of AnimationVector) to start the animation at.
converter: TwoWayConverter<T, V> a TwoWayConverter that converts the from AnimationVector to the animation data type T, and vice versa.

createAnimation

fun FloatDecayAnimationSpec.createAnimation(
    startValue: Float,
    startVelocity: Float = 0f
): Animation<Float, AnimationVector1D>

Creates a Animation (with a fixed start value and start velocity) that decays over time based on the given FloatDecayAnimationSpec.

Parameters
startValue: Float the starting value of the fixed animation.
startVelocity: Float = 0f the starting velocity of the fixed animation.

createAnimation

fun <T> TransitionDefinition<T>.createAnimation(
    clock: AnimationClockObservable,
    initState: T? = null
): TransitionAnimation<T>

Creates a transition animation using the transition definition and the given clock.

Parameters
clock: AnimationClockObservable The clock source for animation to get frame time from.

fling

fun AnimatedFloat.fling(
    startVelocity: Float,
    decay: FloatDecayAnimationSpec = ExponentialDecay(),
    onEnd: OnAnimationEnd? = null
): Unit

Starts a fling animation with the specified starting velocity.

Parameters
startVelocity: Float Starting velocity of the fling animation
decay: FloatDecayAnimationSpec = ExponentialDecay() The decay animation used for slowing down the animation from the starting velocity
onEnd: OnAnimationEnd? = null An optional callback that will be invoked when this fling animation is finished.

fling

fun AnimatedFloat.fling(
    startVelocity: Float,
    decay: FloatDecayAnimationSpec = ExponentialDecay(),
    adjustTarget: (Float) -> TargetAnimation?,
    onEnd: OnAnimationEnd? = null
): Unit

Starts a fling animation with the specified starting velocity.

Parameters
startVelocity: Float Starting velocity of the fling animation
adjustTarget: (Float) -> TargetAnimation? A lambda that takes in the projected destination based on the decay animation, and returns a nullable TargetAnimation object that contains a new destination and an animation to animate to the new destination. This lambda should return null when the original target is respected.
decay: FloatDecayAnimationSpec = ExponentialDecay() The decay animation used for slowing down the animation from the starting velocity
onEnd: OnAnimationEnd? = null An optional callback that will be invoked when the animation finished by any reason.

getVelocity

fun <T, V : AnimationVector> Animation<T, V>.getVelocity(playTime: Long): T

Returns the velocity of the animation at the given play time.

Parameters
playTime: Long the play time that is used to calculate the velocity of the animation.

vectorize

fun <V : AnimationVector> FloatAnimationSpec.vectorize(): AnimationSpec<V>

Create an AnimationSpec that animates AnimationVector from a FloatAnimationSpec. Every dimension of the AnimationVector will be animated using the given FloatAnimationSpec.