การจัดเรียงและการจัดแนว
กำหนดตำแหน่งและระยะห่างขององค์ประกอบลูกอย่างแม่นยำ
การจัดเรียงและการจัดแนว เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Two Words, Two Jobs
Layout control comes down to arrangement and alignment. They sound similar but they do different jobs. Let's untangle them. 🧭
Arrangement: Along the Main Axis
Arrangement controls spacing along the layout's main axis: vertical for a Column, horizontal for a Row.
Alignment: Across the Cross Axis
Alignment controls position on the other axis: horizontal in a Column, vertical in a Row. It lines children up sideways.
Grouping at One End
Arrangement.Top, Center, and Bottom pack children together at one end of a Column, leaving the rest as empty space.
Column(verticalArrangement = Arrangement.Center) {
Text("A")
Text("B")
}Spreading Children Out
Use SpaceBetween, SpaceAround, or SpaceEvenly to distribute extra space among children instead of bunching them up.
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
Text("A")
Text("B")
Text("C")
}SpaceBetween vs SpaceEvenly
SpaceBetween hugs the edges with no outer gaps, while SpaceEvenly adds equal gaps everywhere, including before the first and after the last child.
Fixed Gaps with spacedBy
For a consistent gap, use Arrangement.spacedBy. It inserts the exact distance you give between every adjacent child.
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text("A")
Text("B")
}Column's Cross-Axis Alignment
In a Column the cross axis is horizontal, so horizontalAlignment chooses Start, CenterHorizontally, or End for the children.
Column(horizontalAlignment = Alignment.End) {
Text("Right side")
}Row's Cross-Axis Alignment
In a Row the cross axis is vertical, so verticalAlignment picks Top, CenterVertically, or Bottom for the children.
Row(verticalAlignment = Alignment.Bottom) {
Text("Aligned bottom")
}Combine Both for Layout
You usually set both at once: arrangement spaces children along the main axis while alignment positions them on the cross axis.
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) { Text("Dead center") }Effect Needs Extra Space
Arrangement only shows when the container is bigger than its children. A wrap-content Column has no spare room to redistribute.
Quick Check
Let's confirm which axis each setting controls.
Recap: Arrangement & Alignment
You learned the split: arrangement spaces children along the main axis, alignment positions them on the cross axis. Combine both for precise layouts.
คำถามที่พบบ่อย
บทเรียน “การจัดเรียงและการจัดแนว” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การจัดเรียงและการจัดแนว” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การจัดเรียงและการจัดแนว” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- Column: เรียงสิ่งต่าง ๆ ในแนวตั้ง
- Row: วางสิ่งต่าง ๆ เคียงข้างกัน
- Box: ซ้อนและทับซ้อน
- การจัดเรียงและการจัดแนว