Jetpack Compose LazyColumn reverse display
A

1

6

native composable column with elements a, b and c:

a

b

c

how can you reverse arrangement to:

c

b

a

in android jetpack compose

Asper answered 4/11, 2022 at 19:19 Comment(1)
Reverse the list that has the items you're passing to the column composableUnheard
J
15

You can use LazyColumn's reverseLayout parameter if you want to preserve your collection's structure while having a reversed display.

Say you have these items.

val items = listOf("Apple", "Banana", "Cherry", "Dogs", "Eggs", "Fruits")

ItemList(items = items)

Just set LazyColumn's reverseLayout to true

@Composable
fun ItemList(items: List<String>) {

    LazyColumn(
        reverseLayout = true
    ) {
        items(items) { item ->
            Box(modifier = Modifier
                .height(80.dp)
                .fillMaxWidth()
                .border(BorderStroke(Dp.Hairline, Color.Gray)),
                contentAlignment = Alignment.Center
            ) {
                Text(
                    text = item
                )
            }
        }
    }
}

enter image description here

Janeyjangle answered 4/11, 2022 at 23:32 Comment(1)
If you want list should start from bottom then you should set alignment as bottom. LazyColumn(modifier = Modifier.fillMaxWidth().align(alignment = Alignment.BottomCenter),reverseLayout = true)Ventilation

© 2022 - 2024 — McMap. All rights reserved.