# SpringForce

# SpringForce

Artifact:[androidx.dynamicanimation:dynamicanimation](https://developer.android.com/jetpack/androidx/releases/dynamicanimation)  
[View Source](https://cs.android.com/search?q=file:androidx/dynamicanimation/animation/SpringForce.java+class:androidx.dynamicanimation.animation.SpringForce)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce "View this page in Java")

<br />

```
class SpringForce
```

<br />

*** ** * ** ***

Spring Force defines the characteristics of the spring being used in the animation.

By configuring the stiffness and damping ratio, callers can create a spring with the look and feel suits their use case. Stiffness corresponds to the spring constant. The stiffer the spring is, the harder it is to stretch it, the faster it undergoes dampening.

Spring damping ratio describes how oscillations in a system decay after a disturbance. When damping ratio \>1\* (i.e. over-damped), the object will quickly return to the rest position without overshooting. If damping ratio equals to 1 (i.e. critically damped), the object will return to equilibrium within the shortest amount of time. When damping ratio is less than 1 (i.e. under-damped), the mass tends to overshoot, and return, and overshoot again. Without any damping (i.e. damping ratio = 0), the mass will oscillate forever.

## Summary

|                                      ### Constants                                      |
|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [DAMPING_RATIO_HIGH_BOUNCY](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_HIGH_BOUNCY())` = 0.2f` Damping ratio for a very bouncy spring.        |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [DAMPING_RATIO_LOW_BOUNCY](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_LOW_BOUNCY())` = 0.75f` Damping ratio for a spring with low bounciness. |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [DAMPING_RATIO_MEDIUM_BOUNCY](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_MEDIUM_BOUNCY())` = 0.5f` Damping ratio for a medium bouncy spring.  |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [DAMPING_RATIO_NO_BOUNCY](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_NO_BOUNCY())` = 1.0f` Damping ratio for a spring with no bounciness.     |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [STIFFNESS_HIGH](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_HIGH())` = 10000.0f` Stiffness constant for extremely stiff spring.                   |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [STIFFNESS_LOW](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_LOW())` = 200.0f` Stiffness constant for a spring with low stiffness.                  |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [STIFFNESS_MEDIUM](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_MEDIUM())` = 1500.0f` Stiffness constant for medium stiff spring.                   |
| `const `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [STIFFNESS_VERY_LOW](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_VERY_LOW())` = 50.0f` Stiffness constant for a spring with very low stiffness.    |

|                                                                                                                                 ### Public constructors                                                                                                                                 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#SpringForce())`()` Creates a spring force.                                                                                                                                 |
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#SpringForce(float))`(finalPosition: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Creates a spring with a given final rest position. |

|                                               ### Public functions                                               |
|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                  | [getDampingRatio](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#getDampingRatio())`()` Returns the damping ratio of the spring.                                                                                                                                                                                                                                                              |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                  | [getFinalPosition](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#getFinalPosition())`()` Returns the rest position of the spring.                                                                                                                                                                                                                                                            |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                  | [getStiffness](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#getStiffness())`()` Gets the stiffness of the spring.                                                                                                                                                                                                                                                                           |
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | [setDampingRatio](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#setDampingRatio(float))`(dampingRatio: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Spring damping ratio describes how oscillations in a system decay after a disturbance. |
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | [setFinalPosition](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#setFinalPosition(float))`(finalPosition: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the rest position of the spring.                                                                                                                                                          |
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | [setStiffness](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#setStiffness(float))`(stiffness: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0, fromInclusive = false) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the stiffness of a spring.                                          |

## Constants

### DAMPING_RATIO_HIGH_BOUNCY

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val DAMPING_RATIO_HIGH_BOUNCY = 0.2f: Float
```

Damping ratio for a very bouncy spring. Note for under-damped springs (i.e. damping ratio \<1), the lower the damping ratio, the more bouncy the spring.  

### DAMPING_RATIO_LOW_BOUNCY

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val DAMPING_RATIO_LOW_BOUNCY = 0.75f: Float
```

Damping ratio for a spring with low bounciness. Note for under-damped springs (i.e. damping ratio \<1), the lower the damping ratio, the higher the bounciness.  

### DAMPING_RATIO_MEDIUM_BOUNCY

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val DAMPING_RATIO_MEDIUM_BOUNCY = 0.5f: Float
```

Damping ratio for a medium bouncy spring. This is also the default damping ratio for spring force. Note for under-damped springs (i.e. damping ratio \<1), the lower the damping ratio, the more bouncy the spring.  

### DAMPING_RATIO_NO_BOUNCY

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val DAMPING_RATIO_NO_BOUNCY = 1.0f: Float
```

Damping ratio for a spring with no bounciness. This damping ratio will create a critically damped spring that returns to equilibrium within the shortest amount of time without oscillating.  

### STIFFNESS_HIGH

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val STIFFNESS_HIGH = 10000.0f: Float
```

Stiffness constant for extremely stiff spring.  

### STIFFNESS_LOW

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val STIFFNESS_LOW = 200.0f: Float
```

Stiffness constant for a spring with low stiffness.  

### STIFFNESS_MEDIUM

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val STIFFNESS_MEDIUM = 1500.0f: Float
```

Stiffness constant for medium stiff spring. This is the default stiffness for spring force.  

### STIFFNESS_VERY_LOW

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
const val STIFFNESS_VERY_LOW = 50.0f: Float
```

Stiffness constant for a spring with very low stiffness.  

## Public constructors

### SpringForce

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
SpringForce()
```

Creates a spring force. Note that final position of the spring must be set through[setFinalPosition](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#setFinalPosition(float))before the spring animation starts.  

### SpringForce

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
SpringForce(finalPosition: Float)
```

Creates a spring with a given final rest position.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| `finalPosition: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | final position of the spring when it reaches equilibrium |

## Public functions

### getDampingRatio

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun getDampingRatio(): Float
```

Returns the damping ratio of the spring.  

|                                     Returns                                     |
|---------------------------------------------------------------------------------|-----------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | damping ratio of the spring |

### getFinalPosition

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun getFinalPosition(): Float
```

Returns the rest position of the spring.  

|                                     Returns                                     |
|---------------------------------------------------------------------------------|-----------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | rest position of the spring |

### getStiffness

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun getStiffness(): Float
```

Gets the stiffness of the spring.  

|                                     Returns                                     |
|---------------------------------------------------------------------------------|-----------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | the stiffness of the spring |

### setDampingRatio

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun setDampingRatio(dampingRatio: @FloatRange(from = 0.0) Float): SpringForce!
```

Spring damping ratio describes how oscillations in a system decay after a disturbance.

When damping ratio \>1 (over-damped), the object will quickly return to the rest position without overshooting. If damping ratio equals to 1 (i.e. critically damped), the object will return to equilibrium within the shortest amount of time. When damping ratio is less than 1 (i.e. under-damped), the mass tends to overshoot, and return, and overshoot again. Without any damping (i.e. damping ratio = 0), the mass will oscillate forever.

Default damping ratio is[DAMPING_RATIO_MEDIUM_BOUNCY](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_MEDIUM_BOUNCY()).  

|                                                                                                 Parameters                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| `dampingRatio: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | damping ratio of the spring, it should be non-negative |

|                                                     Returns                                                      |
|------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | the spring force that the given damping ratio is set on |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the {@param dampingRatio} is negative. |

### setFinalPosition

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun setFinalPosition(finalPosition: Float): SpringForce!
```

Sets the rest position of the spring.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|-----------------------------|
| `finalPosition: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | rest position of the spring |

|                                                     Returns                                                      |
|------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | the spring force that the given final position is set on |

### setStiffness

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/dynamicanimation#1.0.0)  

```
fun setStiffness(stiffness: @FloatRange(from = 0.0, fromInclusive = false) Float): SpringForce!
```

Sets the stiffness of a spring. The more stiff a spring is, the more force it applies to the object attached when the spring is not at the final position. Default stiffness is[STIFFNESS_MEDIUM](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_MEDIUM()).  

|                                                                                                           Parameters                                                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| `stiffness: @`[FloatRange](https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange)`(from = 0.0, fromInclusive = false) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | non-negative stiffness constant of a spring |

|                                                     Returns                                                      |
|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
| [SpringForce](https://developer.android.com/reference/kotlin/androidx/dynamicanimation/animation/SpringForce)`!` | the spring force that the given stiffness is set on |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the given spring stiffness is not positive |