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

ระยะขอบ ขนาด และ fillMaxWidth

ควบคุมพื้นที่ภายในและรอบ Composable

ระยะขอบ ขนาด และ fillMaxWidth เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Meet the Modifier

A Modifier is how you adjust a Composable: its size, spacing, and decoration. You chain calls onto it, one tweak at a time. 🧩

Pass It In

Almost every Composable takes a modifier parameter. You pass it as the first thing to change about that element.

Text(
  text = "Hi",
  modifier = Modifier
)

Add Some Padding

Use padding to add empty space around a Composable. It pushes everything else away, giving your element room to breathe.

Text(
  "Hi",
  modifier = Modifier.padding(16.dp)
)

The dp Unit

Sizes use dp, density-independent pixels. They look the same on every screen, so 16.dp is consistent across phones and tablets.

Padding Per Side

You can pad each side differently. Pass horizontal and vertical, or name individual sides like start and top.

Modifier.padding(
  horizontal = 16.dp,
  vertical = 8.dp
)

Set a Fixed Size

Use size to give a Composable an exact width and height. One value makes it square; two values set each dimension.

Modifier.size(width = 120.dp, height = 48.dp)

Width and Height Alone

Need only one dimension? Use width or height on their own and let the other side wrap its content naturally.

Modifier.height(56.dp)

Fill the Width

fillMaxWidth stretches a Composable to take up all the horizontal space its parent offers. Great for full-width buttons and rows.

Modifier.fillMaxWidth()

Fill a Fraction

Pass a fraction to fill only part of the space. fillMaxWidth(0.5f) takes half the available width instead of all of it.

Modifier.fillMaxWidth(0.5f)

Fill Everything

Use fillMaxSize to expand in both directions at once. It is the shortcut for filling width and height together.

Modifier.fillMaxSize()

Chain Them Together

The real power is chaining: stack padding, size, and fill in one fluent call to shape an element exactly how you want.

Modifier
  .fillMaxWidth()
  .padding(16.dp)

Quick Check

Which modifier stretches a Composable across all the horizontal space its parent gives?

Recap

You learned to space, size, and stretch any Composable. padding adds room, size sets exact bounds, and fillMaxWidth grows to fit. ✨

คำถามที่พบบ่อย

บทเรียน “ระยะขอบ ขนาด และ fillMaxWidth” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ระยะขอบ ขนาด และ fillMaxWidth” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ระยะขอบ ขนาด และ fillMaxWidth”

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

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

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

บทเรียน “ระยะขอบ ขนาด และ fillMaxWidth” ใช้เวลานานแค่ไหน

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

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

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

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

  1. ระยะขอบ ขนาด และ fillMaxWidth
  2. พื้นหลัง เส้นขอบ และการตัด
  3. เหตุใดลำดับตัวปรับแต่งจึงสำคัญ
  4. weight และการกำหนดขนาดแบบยืดหยุ่น
← กลับไปที่ Jetpack Compose Academy