android - 如何在 LazyVerticalGrid 中的项目之间显示水平和垂直分隔线?

标签 android android-jetpack-compose

如何在 LazyVerticalGrid 中显示项目之间的垂直和水平分隔线?

对于 LazyColumn 可以这样做:

LazyColumn(...) {
    items(items) { item ->
        Row(item)
        Divider()
    }
}

它也适用于 LazyVerticalGrid 但我不确定如何在项目之间显示垂直分隔线?

最佳答案

您可以在每个单元格中添加 2 个不同的 Divider

类似于:

val numbers = (0..20).toList()

LazyVerticalGrid(cells = GridCells.Fixed(4)){
    itemsIndexed(numbers) { index, item ->

        Row(Modifier.height(IntrinsicSize.Min)) {

            Column(Modifier.weight(1f),horizontalAlignment = Alignment.CenterHorizontally) {
                Text(text = "Number")
                Text(text = "  $item",)
                Divider() //Horizontal divider 
            }
            
            //Vertical divider avoiding the last cell in each row
            if ((index+1)%4 != 0) {
                Column() {
                    Divider(
                        color = Color.Red,
                        modifier = Modifier
                            .fillMaxHeight()
                            .width(1.dp)
                    )
                }
            }
        }
    }
}

enter image description here

关于android - 如何在 LazyVerticalGrid 中的项目之间显示水平和垂直分隔线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67793008/

相关文章:

"intent-filter"中的 android 过滤器 url

android - 使用 firebaserecycleradapter 过滤 recyclerview

android - Onclick用于在java中创建的imageview,而不是xml

android - 如何将线性布局 xml 文件合并到撰写文件中?

android - 如果 android jetpack compose 中的单词太长,则用连字符打破句子行

android - 在一个 Activity 中请求多个 RESTful 调用的最佳方法是什么

java - Android 主屏幕自动滚动页面

android - Jetpack Compose 中一个 ModalBottomSheetLayout 的多个 BottomSheet

带有 Glance 的 Android Widget 为低于 31 的 SDK 提供了便利

android - 我可以在 Jetpack Compose 中使用 Remember 来包装 Modifier 吗?