androidx.compose.foundation.lazy.layout
LazyLayout
Composable function · from org.jetbrains.compose.foundation:foundation:1.12.2
LazyLayout is what LazyColumn, LazyVerticalGrid and HorizontalPager are built on. It creates only the items that are needed, and you decide where each one goes.
You need it only for a scrolling arrangement that none of the lazy lists, grids and pagers can do, like a calendar with items positioned by time, or items on a circle. You handle scrolling yourself.
The parts:
- An item provider knows how many items there are and how to create each one.
- A measure policy decides which items are visible, measures them, and places them.
- Optional prefetch creates items just before they scroll into view.
The API is low level and may still change.
Read more
- LazyLayout reference (Android Developers)
- Custom LazyLayout with Jetpack Compose (Ackee blog): a full example, including scrolling
- Lists and grids (Android Developers): check whether a built-in lazy layout does the job first
Parameters
@Composable
fun LazyLayout(
itemProvider: () -> LazyLayoutItemProvider,
modifier: Modifier = Modifier,
prefetchState: LazyLayoutPrefetchState? = null,
measurePolicy: LazyLayoutMeasurePolicy,
)
itemProvider: () -> LazyLayoutItemProviderRequired
itemProvider: () -> LazyLayoutItemProviderRequiredReturns the provider of the items: the count, and the content of each item by index.
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. Add scrolling here, for example with Modifier.scrollable.
prefetchState: LazyLayoutPrefetchState?Optional
prefetchState: LazyLayoutPrefetchState?OptionalDefault: null
Lets you create items in advance, before they become visible.
measurePolicy: LazyLayoutMeasurePolicyRequired
measurePolicy: LazyLayoutMeasurePolicyRequiredDecides which items to measure and where to place them. Gets the constraints; measure an item with compose(index) and measure.