简体   繁体   中英

Jetpack Compose LazyColumn reverse display

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

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
                )
            }
        }
    }
}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM