0Pricing
Jetpack Compose Academy · Lezione

AnimatedVisibility e Crossfade

Animi la comparsa e la sostituzione dei contenuti.

AnimatedVisibility e Crossfade è una lezione Jetpack Compose Academy gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Jetpack Compose Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Animating What Appears

Sometimes you want content to slide or fade in rather than pop. AnimatedVisibility animates a Composable as it enters and exits the screen. ✨

Wrap What You Show

Give AnimatedVisibility a boolean and a content lambda. When the boolean flips, it animates that content in or out for you.

AnimatedVisibility(visible = show) {
  Text("Hello!")
}

Default Enter and Exit

Out of the box it uses a gentle fade plus expand and shrink. The element appears and disappears smoothly without any extra configuration.

Customize the Entrance

Set the enter parameter to choose how content arrives. Combine transitions like fadeIn and slideInVertically with the plus operator.

enter = fadeIn() + slideInVertically()

Customize the Exit

The exit parameter controls how content leaves. You can mirror the entrance or pick a different effect like shrinkOut for variety.

exit = fadeOut() + shrinkVertically()

Slide, Expand, Scale

Compose ships many transitions: slideIn, expandHorizontally, scaleIn, and their exit pairs. Mix them to design exactly the motion you want.

Swapping Content Smoothly

To replace one Composable with another, reach for Crossfade. It fades the old content out while the new content fades in. 🔀

Crossfade on a Key

Give Crossfade a targetState. Whenever that value changes, it animates between the content produced for the old and new states.

Crossfade(targetState = screen) { current ->
  ScreenFor(current)
}

Great for Tabs and Screens

Crossfade shines when switching between distinct views, like loading versus loaded states or two tabs, giving a polished blend instead of a jarring swap.

Tune the Crossfade Timing

Pass an animationSpec to Crossfade to slow down or speed up the blend. A longer tween makes the transition feel softer and more deliberate.

Crossfade(state, animationSpec = tween(700)) { ... }

Pick the Right Tool

Use AnimatedVisibility to show or hide one thing, and Crossfade to swap between alternatives. Each solves a different appearance problem.

Quick Check

Which Composable smoothly swaps one piece of content for another?

Recap: Enter, Exit, Swap

You now animate appearance with AnimatedVisibility and blend between views with Crossfade, customizing enter, exit, and timing. 🎉

Domande Frequenti

La lezione «AnimatedVisibility e Crossfade» è gratuita?

Sì — il testo completo di «AnimatedVisibility e Crossfade» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Jetpack Compose Academy, passa a CoddyKit PRO. Il corso Jetpack Compose Academy include 4 lezioni in totale.

Cosa imparerò in «AnimatedVisibility e Crossfade»?

Animi la comparsa e la sostituzione dei contenuti. Eserciti Jetpack Compose Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Jetpack Compose Academy?

Non è richiesta alcuna esperienza precedente. Jetpack Compose Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «AnimatedVisibility e Crossfade»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Jetpack Compose Academy?

Sì. Ogni lezione Jetpack Compose Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. animate*AsState per interpolazioni semplici
  2. AnimatedVisibility e Crossfade
  3. updateTransition per movimenti coordinati
  4. Animazioni guidate dai gesti
← Torna a Jetpack Compose Academy