我有一个LazyColumn,在它里面我想显示一个有两个列的水平行,所以我尝试用LazyHorizontalGrid来实现它。但是我的应用程序崩溃时出现了异常-- IllegalArgumentException: LazyHorizontalGrid's height should be bound by parent。下面是我正在使用的代码,请任何人帮助修复它或任何其他方法,通过这些方法我可以使一行有两列。
@Composable
fun HomeItem1() {
Surface(modifier = Modifier.nestedScroll(rememberViewInteropNestedScrollConnection())) {
LazyColumn {
//other contents
item {
LazyHorizontalGrid(
rows = GridCells.Fixed(3),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
items(arrayList.size) {
Text(arrayList[it])
}
}
}
}
}
}发布于 2022-06-21 21:41:24
你需要事先计算网格的高度。
@Composable
fun HomeItem1() {
Surface(modifier = Modifier.nestedScroll(rememberViewInteropNestedScrollConnection())) {
LazyColumn {
//other contents
item {
LazyHorizontalGrid(
modifier = Modifier.height(176.dp), // itemHeight * rowCount + verticalSpacing * (rowCount - 1)
rows = GridCells.Fixed(3),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
items(arrayList.size) {
Text(arrayList[it], modifier = Modifier.height(48.dp))
}
}
}
}
}
}https://stackoverflow.com/questions/72661805
复制相似问题