แกลเลอรี LazyVerticalGrid
จัดรายการในกริดที่เลื่อนได้
แกลเลอรี LazyVerticalGrid เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Grids in Compose
When a screen full of photos needs neat rows and columns, you reach for LazyVerticalGrid. It scrolls vertically and only composes the cells you can see. 🖼️
Why Lazy?
Like LazyColumn, a lazy grid skips off-screen items. A thousand-image gallery stays smooth because Compose builds cells on demand, not all at once.
The Basic Setup
You give LazyVerticalGrid a column count and feed it items. Each item becomes one cell, and Compose flows them left to right, then down.
LazyVerticalGrid(columns = GridCells.Fixed(2)) {
items(photos) { photo ->
PhotoCell(photo)
}
}GridCells.Fixed
Use GridCells.Fixed(n) when you want an exact column count, like a tidy 3-across icon grid that never changes.
columns = GridCells.Fixed(3)Spacing Between Cells
Add breathing room with Arrangement parameters. They control the gap between rows and the gap between columns separately.
LazyVerticalGrid(
columns = GridCells.Fixed(2),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) { }Padding Around the Grid
Use contentPadding to inset the whole grid from the screen edges. It keeps the first and last cells from hugging the borders.
contentPadding = PaddingValues(16.dp)Items From a List
The items builder takes your data list and a cell lambda. Each element of the list maps to exactly one composed cell.
items(galleryPhotos) { photo ->
AsyncImage(model = photo.url, contentDescription = null)
}A Single Special Cell
Need a header or a one-off cell? Use item (singular) for content that should not repeat over your list.
item { GalleryTitle() }
items(photos) { PhotoCell(it) }Spanning Across Columns
A cell can stretch across the whole row with a span. This is perfect for a section title sitting above its photos.
item(span = { GridItemSpan(maxLineSpan) }) {
SectionHeader("Recent")
}Keep Cells Square
Photo galleries look best when cells are square. Apply aspectRatio(1f) to each cell so height tracks its width.
Box(Modifier.aspectRatio(1f)) { PhotoCell(photo) }Grid vs List
Choose a grid when items are visual and equally weighted, like thumbnails. Choose a list when each row is a distinct, full-width record.
Quick Check
A quick one on column counts.
Recap: Grid Galleries
You met LazyVerticalGrid: lazy cells, a column count, spacing, padding, and spans. It is your go-to for scrollable photo galleries. ✨
คำถามที่พบบ่อย
บทเรียน “แกลเลอรี LazyVerticalGrid” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “แกลเลอรี LazyVerticalGrid” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “แกลเลอรี LazyVerticalGrid”
จัดรายการในกริดที่เลื่อนได้ คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “แกลเลอรี LazyVerticalGrid” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม
ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- แกลเลอรี LazyVerticalGrid
- LazyRow สำหรับภาพหมุน
- เซลล์กริดแบบปรับตามขนาดกับแบบคงที่
- สถานะการเลื่อนและการเลื่อนด้วยโปรแกรม