0Pricing
Jetpack Compose Academy · บทเรียน

AnimatedVisibility และ Crossfade

ทำให้การปรากฏและการสลับเนื้อหามีแอนิเมชัน

AnimatedVisibility และ Crossfade เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “AnimatedVisibility และ Crossfade”

ทำให้การปรากฏและการสลับเนื้อหามีแอนิเมชัน คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “AnimatedVisibility และ Crossfade” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม

ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. animate*AsState สำหรับการเปลี่ยนค่าอย่างง่าย
  2. AnimatedVisibility และ Crossfade
  3. updateTransition สำหรับการเคลื่อนไหวที่ประสานกัน
  4. แอนิเมชันที่ขับเคลื่อนด้วยท่าทาง
← กลับไปที่ Jetpack Compose Academy