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

SpringAnimation

class SpringAnimation : DynamicAnimation<SpringAnimation!>
kotlin.Any
   ↳ androidx.dynamicanimation.animation.DynamicAnimation<androidx.dynamicanimation.animation.SpringAnimation>
   ↳ androidx.dynamicanimation.animation.SpringAnimation

SpringAnimation is an animation that is driven by a SpringForce. The spring force defines the spring's stiffness, damping ratio, as well as the rest position. Once the SpringAnimation is started, on each frame the spring force will update the animation's value and velocity. The animation will continue to run until the spring force reaches equilibrium. If the spring used in the animation is undamped, the animation will never reach equilibrium. Instead, it will oscillate forever.

To create a simple SpringAnimation that uses the default SpringForce:

// Create an animation to animate view's X property, set the rest position of the
  // default spring to 0, and start the animation with a starting velocity of 5000 (pixel/s).
  final SpringAnimation anim = new SpringAnimation(view, DynamicAnimation.X, 0)
          .setStartVelocity(5000);
  anim.start();
  

Alternatively, a SpringAnimation can take a pre-configured SpringForce, and use that to drive the animation.

// Create a low stiffness, low bounce spring at position 0.
  SpringForce spring = new SpringForce(0)
          .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY)
          .setStiffness(SpringForce.STIFFNESS_LOW);
  // Create an animation to animate view's scaleY property, and start the animation using
  // the spring above and a starting value of 0.5. Additionally, constrain the range of value for
  // the animation to be non-negative, effectively preventing any spring overshoot.
  final SpringAnimation anim = new SpringAnimation(view, DynamicAnimation.SCALE_Y)
          .setMinValue(0).setSpring(spring).setStartValue(1);
  anim.start();
  

Summary

Inherited constants
Public constructors
<init>(floatValueHolder: FloatValueHolder!)

This creates a SpringAnimation that animates a FloatValueHolder instance.

<init>(floatValueHolder: FloatValueHolder!, finalPosition: Float)

This creates a SpringAnimation that animates a FloatValueHolder instance.

<init>(object: K, property: FloatPropertyCompat<K>!)

This creates a SpringAnimation that animates the property of the given object.

<init>(object: K, property: FloatPropertyCompat<K>!, finalPosition: Float)

This creates a SpringAnimation that animates the property of the given object.

Public methods
Unit
animateToFinalPosition(finalPosition: Float)

Updates the final position of the spring.

Boolean

Queries whether the spring can eventually come to the rest position.

Unit

Cancels the on-going animation.

SpringForce!

Returns the spring that the animation uses for animations.

SpringAnimation!

Uses the given spring as the force that drives this animation.

Unit

Skips to the end of the animation.

Unit

Inherited functions
Extension functions
From androidx.dynamicanimation.animation
SpringAnimation

Updates or applies spring force properties like SpringForce.mDampingRatio, SpringForce.mFinalPosition and stiffness on SpringAnimation.

Inherited properties