Composable Function

LazyLayout

A layout that only composes and lays out currently needed items.

Common
Deprecated Please use overload with LazyLayoutMeasurePolicy

LazyLayout

@ExperimentalFoundationApi
@Composable
fun LazyLayout(
    itemProvider: () -> LazyLayoutItemProvider,
    modifier: Modifier = Modifier,
    prefetchState: LazyLayoutPrefetchState? = null,
    measurePolicy: LazyLayoutMeasureScope.(Constraints) -> MeasureResult,
) = LazyLayout(itemProvider, modifier, prefetchState, LazyLayoutMeasurePolicy(measurePolicy))

A layout that only composes and lays out currently needed items. Can be used to build efficient complex layouts. Currently needed items depend on the LazyLayout implementation, that is, on how the LazyLayoutMeasurePolicy is implemented. Composing items during the measure pass is the signal to indicate which items are "currently needed". In general, only visible items are considered needed, but additional items may be requested by calling LazyLayoutMeasureScope.compose.

This is a low level API for building efficient complex layouts, for a ready-to-use linearly scrollable lazy layout implementation see androidx.compose.foundation.lazy.LazyColumn and androidx.compose.foundation.lazy.LazyRow. For a grid-like scrollable lazy layout, see androidx.compose.foundation.lazy.grid.LazyVerticalGrid and androidx.compose.foundation.lazy.grid.LazyHorizontalGrid. For a pager-like lazy layout, see androidx.compose.foundation.pager.VerticalPager and androidx.compose.foundation.pager.HorizontalPager

For a basic lazy layout sample, see:

For a scrollable lazy layout, see:

Parameters

itemProvider lambda producing an item provider containing all the needed info about the items which could be used to compose and measure items as part of measurePolicy.
modifier to apply on the layout
prefetchState allows to schedule items for prefetching
measurePolicy Measure policy which allows to only compose and measure needed items.

LazyLayout

Common
@Composable
fun LazyLayout(
    itemProvider: () -> LazyLayoutItemProvider,
    modifier: Modifier = Modifier,
    prefetchState: LazyLayoutPrefetchState? = null,
    measurePolicy: LazyLayoutMeasurePolicy,
)

A layout that only composes and lays out currently needed items. Can be used to build efficient complex layouts. Currently needed items depend on the LazyLayout implementation, that is, on how the LazyLayoutMeasurePolicy is implemented. Composing items during the measure pass is the signal to indicate which items are "currently needed". In general, only visible items are considered needed, but additional items may be requested by calling LazyLayoutMeasureScope.compose.

This is a low level API for building efficient complex layouts, for a ready-to-use linearly scrollable lazy layout implementation see androidx.compose.foundation.lazy.LazyColumn and androidx.compose.foundation.lazy.LazyRow. For a grid-like scrollable lazy layout, see androidx.compose.foundation.lazy.grid.LazyVerticalGrid and androidx.compose.foundation.lazy.grid.LazyHorizontalGrid. For a pager-like lazy layout, see androidx.compose.foundation.pager.VerticalPager and androidx.compose.foundation.pager.HorizontalPager

For a basic lazy layout sample, see:

For a scrollable lazy layout, see:

Parameters

itemProvider lambda producing an item provider containing all the needed info about the items which could be used to compose and measure items as part of measurePolicy. This is the bridge between your item data source and the LazyLayout and is implemented as a lambda to promote a performant implementation. State backed implementations of LazyLayoutItemProvider are supported, though it is encouraged to implement this as an immutable entity that will return a new instance in case the dataset updates.
modifier to apply on the layout
prefetchState allows to schedule items for prefetching. See LazyLayoutPrefetchState on how to control prefetching. Passing null will disable prefetching.
measurePolicy Measure policy which allows to only compose and measure needed items.