AnimatedVisibility и Crossfade
Анимируйте появление и замену содержимого.
«AnimatedVisibility и Crossfade» — бесплатный урок Jetpack Compose Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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/7) и разблокировать остальной курс Jetpack Compose Academy, подпишись на CoddyKit PRO. Курс Jetpack Compose Academy содержит 4 уроков всего.
Чему я научусь в уроке «AnimatedVisibility и Crossfade»?
Анимируйте появление и замену содержимого. Ты практикуешь Jetpack Compose Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Jetpack Compose Academy?
Предыдущий опыт не требуется. Jetpack Compose Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.
Сколько времени занимает урок «AnimatedVisibility и Crossfade»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Jetpack Compose Academy?
Да. Каждый урок Jetpack Compose Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- animate*AsState для простых интерполяций
- AnimatedVisibility и Crossfade
- updateTransition для согласованного движения
- Анимации на основе жестов