Google is committed to advancing racial equity for Black communities. See how.

LazyListScope

interface LazyListScope
androidx.compose.foundation.lazy.LazyListScope

Receiver scope which is used by LazyColumn and LazyRow.

Summary

Public methods
abstract Unit
item(content: LazyItemScope.() -> Unit)

Adds a single item to the scope.

abstract Unit
items(items: List<T>, itemContent: LazyItemScope.(item: T) -> Unit)

Adds a list of items and their content to the scope.

abstract Unit
itemsIndexed(items: List<T>, itemContent: LazyItemScope.(index: Int, item: T) -> Unit)

Adds a list of items to the scope where the content of an item is aware of its index.

abstract Unit
stickyHeader(content: LazyItemScope.() -> Unit)

Adds a sticky header item, which will remain pinned even when scrolling after it.

Extension functions
From androidx.paging.compose
Unit
LazyListScope.items(lazyPagingItems: LazyPagingItems<T>, itemContent: LazyItemScope.(value: T?) -> Unit)

Adds the LazyPagingItems and their content to the scope.

Unit
LazyListScope.itemsIndexed(lazyPagingItems: LazyPagingItems<T>, itemContent: LazyItemScope.(index: Int, value: T?) -> Unit)

Adds the LazyPagingItems and their content to the scope where the content of an item is aware of its local index.

Public methods

item

abstract fun item(content: LazyItemScope.() -> Unit): Unit

Adds a single item to the scope.

Parameters
content: LazyItemScope.() -> Unit the content of the item

items

abstract fun <T> items(
    items: List<T>,
    itemContent: LazyItemScope.(item: T) -> Unit
): Unit

Adds a list of items and their content to the scope.

Parameters
items: List<T> the data list
itemContent: LazyItemScope.(item: T) -> Unit the content displayed by a single item

itemsIndexed

abstract fun <T> itemsIndexed(
    items: List<T>,
    itemContent: LazyItemScope.(index: Int, item: T) -> Unit
): Unit

Adds a list of items to the scope where the content of an item is aware of its index.

Parameters
items: List<T> the data list
itemContent: LazyItemScope.(index: Int, item: T) -> Unit the content displayed by a single item
abstract fun stickyHeader(content: LazyItemScope.() -> Unit): Unit

Adds a sticky header item, which will remain pinned even when scrolling after it. The header will remain pinned until the next header will take its place.

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Text

val sections = listOf("A", "B", "C", "D", "E", "F", "G")

LazyColumn {
    sections.forEach { section ->
        stickyHeader {
            Text(
                "Section $section",
                Modifier.fillMaxWidth().background(Color.LightGray).padding(8.dp)
            )
        }
        items((0..9).toList()) {
            Text("Item $it from the section $section")
        }
    }
}
Parameters
content: LazyItemScope.() -> Unit the content of the header