小编May*_*yur的帖子

LazyColumn 内的 LazyHorizo​​ntalGrid

我有一个 LazyColumn,在其中我想显示一个包含两列的水平行,所以我尝试 LazyHorizo​​ntalGrid 来实现它。但我的应用程序崩溃了,但有例外 - 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])
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack android-jetpack-compose

7
推荐指数
1
解决办法
3500
查看次数