Jetpack Compose LazyColumn 反向显示

use*_*510 5 android kotlin android-jetpack-compose lazycolumn android-jetpack-compose-lazy-column

包含元素 a、b 和 c 的本机可组合列:

A

C

你怎样才能扭转安排:

C

A

在 android jetpack 中撰写

z.g*_*g.y 13

LazyColumn's reverseLayout如果您想在反向显示时保留集合的结构,则可以使用参数。

假设你有这些物品。

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

ItemList(items = items)
Run Code Online (Sandbox Code Playgroud)

只需设置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
                )
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述