0Pricing
Jetpack Compose Academy · Lektion

animate*AsState für einfache Tweens

Animieren Sie einen einzelnen Wert automatisch.

animate*AsState für einfache Tweens ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Animation, the Easy Way

Compose can animate changes for you. The simplest tool is the animate*AsState family, which smoothly moves a value from old to new. ✨

What animateDpAsState Does

When your target value changes, animateDpAsState returns a State that glides toward it over a few frames instead of jumping.

val size by animateDpAsState(targetValue = if (big) 200.dp else 100.dp)

Read It Like Normal State

The animated value is just a State you read with by. Use it in a Modifier and the UI follows the animation every frame.

Box(Modifier.size(size).background(Color.Blue))

A Whole Family of Helpers

There is one per type: animateFloatAsState, animateColorAsState, animateDpAsState, and more. Pick the one matching the value you want to tween.

Animate a Color

Use animateColorAsState to fade between colors. Toggle a boolean and watch the background shift smoothly from one tint to another. 🎨

val color by animateColorAsState(if (on) Color.Green else Color.Gray)

Animate Transparency

For fade in and out, animate a float and feed it to alpha. A value of 0f is invisible, 1f is fully opaque.

val a by animateFloatAsState(if (visible) 1f else 0f)
Box(Modifier.alpha(a))

Choose the Pace

Pass an animationSpec to control timing. A tween lets you set the duration in milliseconds and an easing curve.

animateDpAsState(target, animationSpec = tween(durationMillis = 500))

Spring for Bounce

Swap in a spring spec for natural, physics-based motion. Tune dampingRatio and stiffness to add a little playful bounce.

animateDpAsState(target, animationSpec = spring(dampingRatio = 0.4f))

It Reacts to State

You never call start or stop. When the target value changes during recomposition, the animation restarts toward the new goal automatically.

Smooth, Not Linear

Default easing makes motion feel alive by speeding up then slowing down. Easing curves like FastOutSlowInEasing avoid robotic, constant-speed movement.

Listen When It Finishes

Need to react when motion ends? Pass a finishedListener lambda, which fires once with the final value after the animation settles.

animateDpAsState(target) { final -> /* done */ }

Quick Check

Which spec gives motion a natural, bouncy physics feel?

Recap: One Value at a Time

You learned animate*AsState: change a target, read the animated State, and pick tween or spring. It is the quickest way to add smooth single-value motion. 🎉

Häufig gestellte Fragen

Ist die Lektion „animate*AsState für einfache Tweens“ kostenlos?

Ja — der vollständige Text von „animate*AsState für einfache Tweens“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „animate*AsState für einfache Tweens“?

Animieren Sie einen einzelnen Wert automatisch. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?

Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „animate*AsState für einfache Tweens“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?

Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. animate*AsState für einfache Tweens
  2. AnimatedVisibility und Crossfade
  3. updateTransition für koordinierte Bewegungen
  4. Gestengesteuerte Animationen
← Zurück zu Jetpack Compose Academy