[英]Custom Compose Arrangement to add extra spacing at beginning and end of a LazyRow/LazyColumn
How can I create a custom Arrangement
for LazyRow
to add additional spacing at beginning and end, but have even spacing in between?如何为LazyRow
创建自定义Arrangement
以在开头和结尾添加额外的间距,但两者之间的间距均匀?
Start|< more space> Item 1 Item 2 Last Item |End开始|<更多空间> Item 1 Item 2 Last Item |End
object CustomArrangement : Arrangement.Horizontal {
override fun Density.arrange(
totalSize: Int,
sizes: IntArray,
layoutDirection: LayoutDirection,
outPositions: IntArray
) {
}
}
https://developer.android.com/jetpack/compose/lists#custom-arrangements https://developer.android.com/jetpack/compose/lists#custom-arrangements
It is not the answer to your question, but you can achieve the same adding a header and footer items, or using a horizontal PaddingValues
.这不是您问题的答案,但您可以通过添加 header 和页脚项目或使用水平PaddingValues
来实现相同的效果。
A simple LazyRow
:一个简单的LazyRow
:
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 50.dp),
modifier= Modifier.fillMaxSize(),
) {
items(itemsList) {
Text("Item is $it")
}
}
or something like:或类似的东西:
LazyRow(
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier= Modifier.fillMaxSize()
) {
//Header
item(){
Spacer(modifier = Modifier.width(40.dp))
}
items(itemsList) {
Text("Item is $it")
}
//Footer
item(){
Spacer(modifier = Modifier.width(40.dp))
}
}
Maybe you can get the effect you're looking for with one of the paramenters for LazyRow: contentPadding = PaddingValues(horizontal = "your_value")也许您可以使用 LazyRow 的参数之一获得您正在寻找的效果:contentPadding = PaddingValues(horizontal = "your_value")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.