[英]How to add dividers between items in a LazyColumn Jetpack Compose?
I have a LazyColumn that looks like this:我有一个看起来像这样的 LazyColumn:
LazyColumn (
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(bookList) { book ->
InProgressBookItem(book = book)
}
}
How can I add a line between each item in the list, similar to using an item decoration on the old RecyclerView?如何在列表中的每个项目之间添加一条线,类似于在旧的 RecyclerView 上使用项目装饰?
Currently with 1.0.x
you can just add a Divider
in the LazyListScope
.目前在1.0.x
中,您只需在LazyListScope
中添加一个Divider
即可。
Something like:就像是:
LazyColumn(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
items(itemsList){
Text("Item at $it")
Divider(color = Color.Black)
}
}
If you want to avoid the Divider
in the last items you can use:如果你想避免在最后一个项目中使用Divider
,你可以使用:
LazyColumn(
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
itemsIndexed(itemsList) { index, item ->
Text("Item at index $index is $item")
if (index < itemsList.size-1)
Divider(color = Color.Black, thickness = 1.dp)
}
}
Simple:简单的:
LazyColumn (
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(bookList) { book ->
InProgressBookItem(book = book)
Divider(color = Color.Black, thickness = 1.dp)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.