简体   繁体   English

Jetpack Compose LazyColumn 反向展示

[英]Jetpack Compose LazyColumn reverse display

native composable column with elements a, b and c:包含元素 a、b 和 c 的原生可组合列:

a一种

b b

c c

how can you reverse arrangement to:你怎么能颠倒安排:

c c

b b

a一种

in android jetpack compose在 android 喷气背包中

You can use LazyColumn's reverseLayout parameter if you want to preserve your collection's structure while having a reversed display.如果您想在反转显示的同时保留集合的结构,则可以使用LazyColumn's reverseLayout参数。

Say you have these items.假设您有这些物品。

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

ItemList(items = items)

Just set LazyColumn's reverseLayout to true只需将LazyColumn's reverseLayout设置为 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
                )
            }
        }
    }
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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