# 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)

*** ** * ** ***


```
public final 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 |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_HIGH_BOUNCY() = 0.2f` Damping ratio for a very bouncy spring. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_LOW_BOUNCY() = 0.75f` Damping ratio for a spring with low bounciness. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_MEDIUM_BOUNCY() = 0.5f` Damping ratio for a medium bouncy spring. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_NO_BOUNCY() = 1.0f` Damping ratio for a spring with no bounciness. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_HIGH() = 10000.0f` Stiffness constant for extremely stiff spring. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_LOW() = 200.0f` Stiffness constant for a spring with low stiffness. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_MEDIUM() = 1500.0f` Stiffness constant for medium stiff spring. |
| `static final float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_VERY_LOW() = 50.0f` Stiffness constant for a spring with very low stiffness. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#SpringForce()()` Creates a spring force. |
| `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#SpringForce(float)(float finalPosition)` Creates a spring with a given final rest position. |

| ### Public methods |
|---|---|
| `float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#getDampingRatio()()` Returns the damping ratio of the spring. |
| `float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#getFinalPosition()()` Returns the rest position of the spring. |
| `float` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#getStiffness()()` Gets the stiffness of the spring. |
| `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#setDampingRatio(float)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float dampingRatio)` Spring damping ratio describes how oscillations in a system decay after a disturbance. |
| `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#setFinalPosition(float)(float finalPosition)` Sets the rest position of the spring. |
| `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce` | `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#setStiffness(float)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false) float stiffness)` 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)

```
public static final float DAMPING_RATIO_HIGH_BOUNCY = 0.2f
```

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)

```
public static final float DAMPING_RATIO_LOW_BOUNCY = 0.75f
```

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)

```
public static final float DAMPING_RATIO_MEDIUM_BOUNCY = 0.5f
```

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)

```
public static final float DAMPING_RATIO_NO_BOUNCY = 1.0f
```

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)

```
public static final float STIFFNESS_HIGH = 10000.0f
```

Stiffness constant for extremely stiff spring.

### STIFFNESS_LOW

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

```
public static final float STIFFNESS_LOW = 200.0f
```

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)

```
public static final float STIFFNESS_MEDIUM = 1500.0f
```

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)

```
public static final float STIFFNESS_VERY_LOW = 50.0f
```

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)

```
public SpringForce()
```

Creates a spring force. Note that final position of the spring must be set through `https://developer.android.com/reference/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)

```
public SpringForce(float finalPosition)
```

Creates a spring with a given final rest position.

| Parameters |
|---|---|
| `float finalPosition` | final position of the spring when it reaches equilibrium |

## Public methods

### getDampingRatio

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

```
public float getDampingRatio()
```

Returns the damping ratio of the spring.

| Returns |
|---|---|
| `float` | damping ratio of the spring |

### getFinalPosition

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

```
public float getFinalPosition()
```

Returns the rest position of the spring.

| Returns |
|---|---|
| `float` | rest position of the spring |

### getStiffness

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

```
public float getStiffness()
```

Gets the stiffness of the spring.

| Returns |
|---|---|
| `float` | the stiffness of the spring |

### setDampingRatio

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

```
public SpringForce setDampingRatio(@FloatRange(from = 0.0) float dampingRatio)
```

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 `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#DAMPING_RATIO_MEDIUM_BOUNCY()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float dampingRatio` | damping ratio of the spring, it should be non-negative |

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

| Throws |
|---|---|
| `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)

```
public SpringForce setFinalPosition(float finalPosition)
```

Sets the rest position of the spring.

| Parameters |
|---|---|
| `float finalPosition` | rest position of the spring |

| Returns |
|---|---|
| `https://developer.android.com/reference/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)

```
public SpringForce setStiffness(@FloatRange(from = 0.0, fromInclusive = false) float stiffness)
```

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 `https://developer.android.com/reference/androidx/dynamicanimation/animation/SpringForce#STIFFNESS_MEDIUM()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false) float stiffness` | non-negative stiffness constant of a spring |

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

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