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

KeyframesSpec

class KeyframesSpec<V : AnimationVector> : DurationBasedAnimationSpec<V>
kotlin.Any
   ↳ androidx.animation.KeyframesSpec

KeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.e. different keyframes). Each keyframe can be provided via keyframes parameter. KeyframesSpec allows very specific animation definitions with a precision to millisecond.

Here's an example of creating a KeyframesSpec animation: (KeyframesBuilder could make defining key frames more readable.)

    val delay = 120L
    val startValue = AnimationVector3D(100f, 200f, 300f)
    val endValue = AnimationVector3D(200f, 100f, 0f)
    val keyframes = Keyframes<AnimationVector3D>(
         mutableMapOf (
              0L to (startValue to LinearEasing),
              100L to (startValue to FastOutLinearInEasing)
         ),
         200L,
         delay
    )

Summary

Public constructors
<init>(keyframes: Map<Long, Pair<V, Easing>>, duration: Long, delay: Long = 0L)

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

Public methods
V
getValue(playTime: Long, start: V, end: V, startVelocity: V)

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

V
getVelocity(playTime: Long, start: V, end: V, startVelocity: V)

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Inherited functions
Inherited extension functions
From androidx.animation
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.

Properties
Long

the amount of the time the animation should wait before it starts.

Long

total duration of the animation

Public constructors

<init>

KeyframesSpec(
    keyframes: Map<Long, Pair<V, Easing>>,
    duration: Long,
    delay: Long = 0L)

KeyframesSpec class manages the animation based on the values defined at different timestamps in the duration of the animation (i.e. different keyframes). Each keyframe can be provided via keyframes parameter. KeyframesSpec allows very specific animation definitions with a precision to millisecond.

Here's an example of creating a KeyframesSpec animation: (KeyframesBuilder could make defining key frames more readable.)

    val delay = 120L
    val startValue = AnimationVector3D(100f, 200f, 300f)
    val endValue = AnimationVector3D(200f, 100f, 0f)
    val keyframes = Keyframes<AnimationVector3D>(
         mutableMapOf (
              0L to (startValue to LinearEasing),
              100L to (startValue to FastOutLinearInEasing)
         ),
         200L,
         delay
    )
Parameters
keyframes: Map<Long, Pair<V, Easing>> a map from time to a value/easing function pair. The value in each entry defines the animation value at that time, and the easing curve is used in the interval starting from that time.
duration: Long total duration of the animation
delay: Long = 0L the amount of the time the animation should wait before it starts. Defaults to 0.

See Also

Public methods

getValue

fun getValue(
    playTime: Long,
    start: V,
    end: V,
    startVelocity: V
): V

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTime: Long time since the start of the animation
start: V start value of the animation
end: V end value of the animation
startVelocity: V start velocity of the animation

getVelocity

fun getVelocity(
    playTime: Long,
    start: V,
    end: V,
    startVelocity: V
): V

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

Parameters
playTime: Long time since the start of the animation
start: V start value of the animation
end: V end value of the animation
startVelocity: V start velocity of the animation

Properties

delay

val delay: Long

the amount of the time the animation should wait before it starts. Defaults to 0.

duration

val duration: Long

total duration of the animation