แถวสถิติและปุ่มติดตาม
เพิ่มรายละเอียดแบบโต้ตอบให้การ์ด
แถวสถิติและปุ่มติดตาม เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Add the Interactive Details
With the header done, you will add the lower half: a row of stats and a follow button that responds to taps. This is where the card comes alive. ⚡
One Stat Block
Each stat is two stacked Texts: a big number and a small label. A tiny Column holds them together as one neat block.
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("128")
Text("Posts")
}Emphasize the Number
The count should pop while the label stays quiet. Give the number a bold style and the label a smaller one.
Text("128", style = MaterialTheme.typography.titleMedium)
Text("Posts", style = MaterialTheme.typography.labelSmall)Put Stats in a Row
Three stat blocks sit side by side, so wrap them in a Row. Each block becomes a child laid out left to right.
Row {
StatBlock("128", "Posts")
StatBlock("4.2k", "Followers")
StatBlock("180", "Following")
}Space the Stats Evenly
Spread the blocks across the card with Arrangement.SpaceEvenly on the Row, so the gaps are equal and balanced.
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) { /* ... */ }Add the Follow Button
Below the stats, add a Button. Its onClick lambda runs your code the moment the user taps it.
Button(onClick = { /* follow */ }) {
Text("Follow")
}Make It Full Width
A primary action button reads best across the whole card. Add fillMaxWidth so it spans edge to edge.
Button(
onClick = { /* follow */ },
modifier = Modifier.fillMaxWidth()
) { Text("Follow") }Track the Follow State
The button should toggle between Follow and Following. Hold that with remember and mutableStateOf so the UI reacts to taps.
var following by remember { mutableStateOf(false) }Flip State on Tap
Inside onClick, flip the boolean. Compose notices the state changed and redraws the button with new text automatically.
Button(onClick = { following = !following }) {
Text(if (following) "Following" else "Follow")
}Wire It Into the Card
Drop the stats Row and the Button below the header inside the outer Column. The full card now reads top to bottom in order.
An Interactive Card
You now have stats, a follow button, and live state. Tapping really changes the screen, which is the heart of a declarative Compose UI. 🎉
Quick Check
What lets the button text update when tapped?
Recap: Stats and Action
You built a Row of evenly spaced stat blocks and a full-width follow button driven by remembered state. Next you will refactor it all into clean, reusable pieces.
คำถามที่พบบ่อย
บทเรียน “แถวสถิติและปุ่มติดตาม” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “แถวสถิติและปุ่มติดตาม” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “แถวสถิติและปุ่มติดตาม”
เพิ่มรายละเอียดแบบโต้ตอบให้การ์ด คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “แถวสถิติและปุ่มติดตาม” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ร่างเลย์เอาต์การ์ดโปรไฟล์
- ส่วนรูปประจำตัว ชื่อ และประวัติ
- แถวสถิติและปุ่มติดตาม
- แยก Composable ที่นำกลับมาใช้ใหม่ได้