Skip to the workspace
Pebellslearn by building
Building Screens with Jetpack Compose  ›  Capstone Project

Cards and Lazy Lists

Card 16 minA Card groups one item's content on a raised surface, and LazyColumn shows long lists efficiently by composing only the items that are visible.

android / Cards and Lazy Lists

Explore each scene at your own pace.

01 · The rule

The rule

Cards and Lazy Lists

Sprout's home screen is a list of plants, each on its own card. With five plants anything works. With three hundred, the wrong choice makes scrolling stutter. This lesson brings together everything in the section: text, icons, layouts and state, inside a fast list.

The rule

A Card holds one thing; a lazy list only builds what you can see.

Card is a Material surface with rounded corners and a subtle elevation or outline. It groups one item's content, and its inside is a normal content slot:

@Composable
fun PlantCard(plant: Plant, onClick: () -> Unit) {
    Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
        Column(Modifier.padding(16.dp)) {
            Text(plant.name, style = MaterialTheme.typography.titleMedium)
            Text("Water every ${plant.days} days")
        }
    }
}

LazyColumn is the list container. A plain Column composes every child immediately, including ones far below the screen. LazyColumn composes only the items currently visible (plus a few nearby) and creates more as the user scrolls. LazyRow does the same horizontally.

LazyColumn(contentPadding = PaddingValues(16.dp)) {
    items(plants, key = { it.id }) { plant ->
        PlantCard(plant, onClick = { open(plant.id) })
    }
}
  • items(list) creates one entry per element.
  • key gives each entry a stable identity, so when a plant is added or removed, the others keep their state and animate correctly.

Note that you cannot call composables directly inside LazyColumn's lambda: it is a list builder, not a composable body, so entries are added with items or item.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.