Linear interpolation. Given a start, an end, and a fraction t ∈ [0,1], lerp returns a value in between:
lerp(a, b, t) = a + (b - a) * t
t = 0➜ startt = 1➜ endt = 0.5➜ the midpointt < 0ort > 1➜ extrapolation (useful for overshoot)
Compose includes overloads for common types:
lerp(start: Float, end: Float, t)lerp(start: Dp, end: Dp, t)lerp(start: Offset, end: Offset, t)lerp(start: Color, end: Color, t)(inandroidx.compose.ui.graphics)
- Sync multiple properties with one timeline (
t) - Build custom motion without complex transitions
- Morph shapes, positions, colors, sizes—all in sync
A single fraction animates:
- position (
Offset) - size (
Dp) - corner radius (
Dp) - color (
Color)
👉 See LerpBasicsDemo.kt for the full runnable code.
- Clamp
tif you want strict bounds; allow overshoot for playful effects. - Use easing curves to map time ➜ fraction.
- Drive everything from one
Animatable(0f..1f)for synchronized motion.