I try to use LazyHorizontalGrid with 2 fixed rows inside a LazyColumn. 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.
The LazyColumn
wraps the height of the content and can be stretched and in this way the item
scope has constraints.maxHeight = Constraints.Infinity
. The sum of the rows' height in the LazyHorizontalGrid
can't be Constraints.Infinity
. It is the reason of the issue.
You have to assign a max height
to your LazyHorizontalGrid
.
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.