【问题标题】:How to limit items count in LazyColumn?如何限制 LazyColumn 中的项目数?
【发布时间】:2021-12-23 10:05:04
【问题描述】:

我想在下面的代码中将 LazyColumn 中的项目限制为 3 个,

@Composable
fun MessageList(messages: List<Message>) {
    LazyColumn {
        items(
            items = messages,
            key = { message ->
                // Return a stable + unique key for the item
                message.id
            }
        ) { message ->
            MessageRow(message)
        }
    }
}

【问题讨论】:

    标签: android android-jetpack-compose


    【解决方案1】:

    如果你只想要 3 个项目,那么替换

    items = messages
    

    items = messages.take(3)
    

    【讨论】:

      猜你喜欢
      • 2022-10-04
      • 2021-12-08
      • 2021-04-16
      • 2021-09-10
      • 1970-01-01
      • 2021-11-30
      • 2021-10-17
      • 2022-12-03
      • 2023-01-19
      相关资源
      最近更新 更多