[英]Using LazyHorizontalGrid inside LazyColumn
I try to use LazyHorizontalGrid with 2 fixed rows inside a LazyColumn.我尝试在 LazyColumn 中使用带有 2 个固定行的 LazyHorizontalGrid。 But then app crashes:但随后应用程序崩溃:
IllegalArgumentException: LazyHorizontalGrid's height should be bound by parent
This is surprising, as I can use LazyRow inside a LazyColumn without any problem.这是令人惊讶的,因为我可以毫无问题地在 LazyColumn 中使用 LazyRow。
The LazyColumn
wraps the height of the content and can be stretched and in this way the item
scope has constraints.maxHeight = Constraints.Infinity
. LazyColumn
包裹了内容的高度并且可以被拉伸,这样item
scope 就有了constraints.maxHeight = Constraints.Infinity
。 The sum of the rows' height in the LazyHorizontalGrid
can't be Constraints.Infinity
. LazyHorizontalGrid
中行高的总和不能是Constraints.Infinity
。 It is the reason of the issue.这是问题的原因。
You have to assign a max height
to your LazyHorizontalGrid
.您必须为LazyHorizontalGrid
分配最大height
。
LazyColumn {
item {
LazyHorizontalGrid(
rows = GridCells.Fixed(3),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.heightIn(max = 200.dp)
) {
// item content
}
}
items(itemsList) {
item content
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.