pro*_*lav 6 android kotlin android-jetpack android-jetpack-compose
我用来LazyVerticalGrid
创建一个具有 96 dp 列的响应式网格,它看起来像这样:
LazyVerticalGrid(
columns = GridCells.Adaptive(96.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Card {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Card {...}
Text(title)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但存在一个问题:由于文本换行,卡片内容可能具有不同的高度,并且卡片之间存在负空间(用红色箭头标记)。哪些解决方案可以在 Compose 中实现而无需创建自定义布局?
LazyHorizontalStaggeredGrid 可能适合您。
val itemsIndexedList = listOf("A", "B", "C")
LazyHorizontalStaggeredGrid(
rows = StaggeredGridCells.Fixed(3)
) {
itemsIndexed(itemsIndexedList) { index, item ->
Text("Item at index $index is $item")
}
}
Run Code Online (Sandbox Code Playgroud)
欲了解更多详情,请查看下面的链接。 https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/staggeredgrid/package-summary#LazyVerticalStaggeredGrid
归档时间: |
|
查看次数: |
2391 次 |
最近记录: |