Jetpack Compose Academy · Lektion

LazyVerticalGrid-Galerien

Ordnen Sie Elemente in einem scrollbaren Grid an.

Lektion 1 von 413 Schritte

LazyVerticalGrid-Galerien ist eine kostenlose Jetpack Compose Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Jetpack Compose Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

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. ✨

Kostenlos starten

Lerne Kotlin mit einem KI-Tutor — kostenlos

Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.

Kurse
30
Lektionen
120

Häufig gestellte Fragen

Ist die Lektion „LazyVerticalGrid-Galerien“ kostenlos?

Ja — der vollständige Text von „LazyVerticalGrid-Galerien“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Jetpack Compose Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Jetpack Compose Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „LazyVerticalGrid-Galerien“?

Ordnen Sie Elemente in einem scrollbaren Grid an. Du übst Jetpack Compose Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Jetpack Compose Academy zu starten?

Keine Vorkenntnisse erforderlich. Jetpack Compose Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „LazyVerticalGrid-Galerien“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Jetpack Compose Academy-Lektion Code schreiben und ausführen?

Ja. Jede Jetpack Compose Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. LazyVerticalGrid-Galerien
  2. LazyRow für Karussells
  3. Adaptive und feste Grid-Zellen
  4. Scroll-State und programmgesteuertes Scrollen
← Zurück zu Jetpack Compose Academy