gpt4 book ai didi

android - 撰写 LazyList 部分背景

转载 作者:行者123 更新时间:2023-12-04 23:39:57 28 4
gpt4 key购买 nike

我很难确定我的问题是 Jetpack Compose 缺少功能还是我找不到它是如何完成的。
假设我想做这个页面
enter image description here
它需要可滚动,因为内容很长。
我还想使用惰性列来加载图像中显示的用户列表。
问题是您不能在垂直可滚动布局中使用 LazyColumn,所以我想我只需将整个页面设置为 LazyColumn。
现在还有另一个问题,我希望用户列表周围有一个带有背景颜色和圆形边框的框,如图所示,但是您不能在 LazyListScope.items() 周围放置一个框,并且如果您将列表加载为像 item { UserList() } 这样的单个可组合然后它只是使它成为一个列,失去了惰性部分。
如何做到这一点?

最佳答案

如果我正确理解了问题,您需要做的是分别定义您在 LazyColumn 中代表的“项目”的布局。
举个例子,你有一些讲座要在你的列表中展示。您可以定义它的方式是:

LazyColumn(
//modifiers etc
) {
items(
items = **lectures** -> your list of items,
itemContent = {
**LectureListItem**(it) -> your specified layout
}
)
}
在你下面创建你的可组合 LectureListItem它具有您想要的布局(无论是框、列、行以及其中的所有内容)。例子:
@Composable
fun LectureListItem(
lecture: Lecture
) {
Box(
modifier = Modifier
.padding(8.dp)
.background(//exampleColor)
) {
//Other elements of your layout
}
}

关于android - 撰写 LazyList 部分背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68182413/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com