AnimatedVisibilityとCrossfade
表示とコンテンツの切り替えをアニメーション化します。
「AnimatedVisibilityとCrossfade」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. 🎉
よくある質問
「AnimatedVisibilityとCrossfade」レッスンは無料ですか?
はい。「AnimatedVisibilityとCrossfade」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「AnimatedVisibilityとCrossfade」で何を学びますか?
表示とコンテンツの切り替えをアニメーション化します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「AnimatedVisibilityとCrossfade」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 単純な補間にanimate*AsStateを使う
- AnimatedVisibilityとCrossfade
- 連動した動きにupdateTransitionを使う
- ジェスチャー駆動アニメーション