我有一个屏幕,需要显示一个标题和一个包含项目的卡片视图。整个屏幕都需要可滚动(如下图所示)。
我知道如何使用可滚动的Column来实现这个,但我想要使用
那段代码的问题在于我无法将列表项包装在卡片视图中,因为
LazyColumn
(因为每个列表项都有自己的ViewModel,由于视图的复杂性,我认为LazyColumn会更加节约资源)。对于标题,我可以使用item
,对于列表,我可以使用items
。以下是我尝试的代码:@Composable
fun Screen(
items: List<String>
) {
Column(
Modifier.fillMaxSize()
) {
TopAppBar(title = { Text(text = "My Activity") })
LazyColumn {
// Header
item {
Text("Title", Modifier.padding(32.dp))
}
// I cannot use Box in this way here
Box(Modifier.padding(32.dp)) {
Card {
items(items.size) {
Text("Item $it")
}
}
}
}
}
}
那段代码的问题在于我无法将列表项包装在卡片视图中,因为
Card
不是LazyListScope
。使用LazyColumn
,我该如何将列表项包装在卡片中?