[英]How to create GridLayout using JetpackCompose?
<androidx.gridlayout.widget.GridLayout>
...
</androidx.gridlayout.widget.GridLayout>
In the grid layout, each column will automatically adapt to the widest view.在网格布局中,每一列都会自动适应最宽的视图。
In JetpackCompose, I can only use:在 JetpackCompose 中,我只能使用:
Column {
Box{
Text()
Text(modifier = Modifier.padding(start = xxxxxx))
}
...
}
Is there a better way?有没有更好的办法?
If you want a Lazy Grid, you can use the Lazy Grids as shown here :如果你想要一个惰性网格,你可以使用如下所示 的惰性网格:
@Composable
fun PhotoGrid(photos: List<Photo>) {
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 128.dp)
) {
items(photos) { photo ->
PhotoItem(photo)
}
}
}
If you don't want it Lazy, you can use the sample Grid.kt designed by the Jetpack Compose team in one of their sample apps:如果您不想让它 Lazy,您可以使用 Jetpack Compose 团队在其示例应用程序之一中设计的示例Grid.kt :
@Composable
fun PhotoGrid(photos: List<Photo>) {
VerticalGrid(
columns = 2
) {
items(photos) { photo ->
PhotoItem(photo)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.