New Compose Multiplatform components arrived on Composables UICheck it out →

LazyRow

The horizontally scrolling list that only composes and lays out the currently visible items. The [content] block defines a DSL which allows you to emit items of different types. For example you can use [LazyListScope.item] to add a single item and [LazyListScope.items] to add a list of items.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.7.0-beta03")
}

Overloads

@Composable
fun LazyRow(
    modifier: Modifier = Modifier,
    state: LazyListState = rememberLazyListState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    reverseLayout: Boolean = false,
    horizontalArrangement: Arrangement.Horizontal =
        if (!reverseLayout) Arrangement.Start else Arrangement.End,
    verticalAlignment: Alignment.Vertical = Alignment.Top,
    flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
    userScrollEnabled: Boolean = true,
    content: LazyListScope.() -> Unit
)

Parameters

namedescription
modifierthe modifier to apply to this layout
statethe state object to be used to control or observe the list's state
contentPaddinga padding around the whole content. This will add padding for the content after it has been clipped, which is not possible via [modifier] param. You can use it to add a padding before the first item or after the last one. If you want to add a spacing between each item use [horizontalArrangement].
reverseLayoutreverse the direction of scrolling and layout. When true, items are laid out in the reverse order and [LazyListState.firstVisibleItemIndex] == 0 means that row is scrolled to the end. Note that [reverseLayout] does not change the behavior of [horizontalArrangement], e.g. with [Arrangement.Start] [123###] becomes [321###].
horizontalArrangementThe horizontal arrangement of the layout's children. This allows to add a spacing between items and specify the arrangement of the items when we have not enough of them to fill the whole minimum size.
verticalAlignmentthe vertical alignment applied to the items
flingBehaviorlogic describing fling behavior.
userScrollEnabledwhether the scrolling via the user gestures or accessibility actions is allowed. You can still scroll programmatically using the state even when it is disabled.
contenta block which describes the content. Inside this block you can use methods like [LazyListScope.item] to add a single item or [LazyListScope.items] to add a list of items.
@Composable
@Deprecated("Use the non deprecated overload", level = DeprecationLevel.HIDDEN
fun LazyRow(
    modifier: Modifier = Modifier,
    state: LazyListState = rememberLazyListState(),
    contentPadding: PaddingValues = PaddingValues(0.dp),
    reverseLayout: Boolean = false,
    horizontalArrangement: Arrangement.Horizontal =
        if (!reverseLayout) Arrangement.Start else Arrangement.End,
    verticalAlignment: Alignment.Vertical = Alignment.Top,
    flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
    content: LazyListScope.() -> Unit
)

Code Example

LazyRowSample

@Composable
@Sampled
fun LazyRowSample() {
    val itemsList = (0..5).toList()
    val itemsIndexedList = listOf("A", "B", "C")

    LazyRow {
        items(itemsList) {
            Text("Item is $it")
        }

        item {
            Text("Single item")
        }

        itemsIndexed(itemsIndexedList) { index, item ->
            Text("Item at index $index is $item")
        }
    }
}