如何在不使用回收 View 或 android.widget.gridview 的情况下在 Jetpack compose 中创建 Gridview?
最佳答案
1.x.y
LazyVerticalGrid
composable 为在网格中显示项目提供实验性支持。
val numbers = (0..20).toList()
LazyVerticalGrid(
columns = GridCells.Fixed(4)
) {
items(numbers.size) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "Number")
Text(text = " $it",)
}
}
}
columns = GridCells.Fixed(4)
意味着有 4 列占父级宽度的 1/4。
val numbers = (0..20).toList()
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 64.dp)
) {
items(numbers) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "Number")
Text(text = " $it",)
}
}
}
columns = GridCells.Adaptive(minSize = 64.dp)
意味着将有尽可能多的列,每列至少为 64.dp,并且所有列都将相等宽度。
关于android - 如何使用 Jetpack Compose 创建 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596541/