Sami Shorman
Sami Shorman

Reputation: 158

How to change layoutManger for lazyColoumn in jetpack compose(vertical ,horizontal ,grid)

I want to change LayoutManger(I don't know what that is called in jetpack compose) for LazyColumn so I can make the items scroll horizontally or vertically or in grid.

Upvotes: 0

Views: 2684

Answers (2)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364441

With 1.0.0 you can use:

  • LazyColumn : produces a vertically scrolling list
  • LazyRow: produces a horizontally scrolling list

Something like:

LazyColumn {    
   items((1..1000).toList()) {
            Text(text = "Item $it")
        }
}
  • the LazyVerticalGrid provides experimental support for displaying items in a grid.

Something like:

val numbers = (0..20).toList()

LazyVerticalGrid(
    cells = GridCells.Fixed(4)
) {
    items(numbers) {
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            Text(text = "Number")
            Text(text = "  $it",)
        }
    }
}

Upvotes: 4

Varsha Kulkarni
Varsha Kulkarni

Reputation: 1574

In Jetpack Compose you can use LazyRow for horizontal scroll. LazyVerticalGrid can be used for Grid, which is still an experimental API. Read more here. This for complete details about lists. Official Jetpack Compose samples

Upvotes: 2

Related Questions