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

เซลล์กริดแบบปรับตามขนาดกับแบบคงที่

ทำให้กริดตอบสนองต่อความกว้างหน้าจอ

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

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

Two Ways to Size Cells

A grid needs to know how wide its columns are. Compose offers two strategies: Fixed column counts and Adaptive minimum widths. 📐

Fixed Recap

You already met GridCells.Fixed(n). It always shows n columns, so cells grow or shrink to fit the screen width.

columns = GridCells.Fixed(3)

The Problem With Fixed

On a phone, 3 columns look great. On a tablet, those same 3 columns become awkwardly wide. Fixed does not adapt to bigger screens.

Enter Adaptive

With GridCells.Adaptive(minSize), you specify a minimum cell width. Compose fits as many columns as possible, then stretches them to fill.

columns = GridCells.Adaptive(minSize = 120.dp)

How Adaptive Counts

Compose divides the available width by your minSize to decide the column count. A wider screen simply gets more columns, automatically.

Responsive by Default

Adaptive grids look right on phones, foldables, and tablets without any extra code. One minSize value handles every screen. 📱

Choosing a minSize

Pick a minSize that keeps content readable at its smallest. Too tiny and cells feel cramped; too large and small phones show one column.

GridCells.Adaptive(minSize = 96.dp)

When Fixed Still Wins

Use Fixed when the design demands an exact count, like a 7-day calendar week that must always be 7 columns wide.

GridCells.Fixed(7)

Mixing With Spacing

Both strategies pair with arrangements. The minSize in Adaptive is measured before spacing, so leave room for your gaps.

LazyVerticalGrid(
    columns = GridCells.Adaptive(120.dp),
    horizontalArrangement = Arrangement.spacedBy(8.dp)
) { }

LazyHorizontalGrid Too

The same Fixed and Adaptive cells work in LazyHorizontalGrid, which scrolls sideways and fills rows top to bottom.

LazyHorizontalGrid(rows = GridCells.Adaptive(80.dp)) { }

A Simple Rule

Default to Adaptive for content galleries so they scale across devices. Reserve Fixed for layouts that need a precise, meaningful column count.

Quick Check

Pick the responsive choice.

Recap: Sizing Cells

You compared Fixed exact counts with Adaptive minimum widths. Adaptive scales across devices; Fixed locks an intentional column count. 🎯

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

บทเรียน “เซลล์กริดแบบปรับตามขนาดกับแบบคงที่” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “เซลล์กริดแบบปรับตามขนาดกับแบบคงที่” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. แกลเลอรี LazyVerticalGrid
  2. LazyRow สำหรับภาพหมุน
  3. เซลล์กริดแบบปรับตามขนาดกับแบบคงที่
  4. สถานะการเลื่อนและการเลื่อนด้วยโปรแกรม
← กลับไปที่ Jetpack Compose Academy