https://kotlinlang.org logo
#compose
Title
# compose
f

Florian

12/10/2021, 11:33 AM
How can I separate items in a LazyVerticalGrid with Dividers? Adding a horizontal line between each row is easy but I don't know how to separate the columns with vertical lines. Using a Box with a border doesn't work well because the start/end borders add up.
1
a

allan.conda

12/10/2021, 8:42 PM
Cut the border size in half so it adds up correctly, or just render it correctly based on the column index
c

Colton Idle

12/11/2021, 6:31 AM
Just always show a border bottom and border right except for the last column and the last row?
c

Chris Sinco [G]

12/12/2021, 5:31 PM
If the columns are fixed (not adaptive), you could use a vertical Divider:
Divider(Modifier.width(1.dp).fillMaxHeight())
f

Florian

12/13/2021, 7:26 PM
the grid is adaptive tho 😕
and I guess I can't know when an item is the last in a row
a

allan.conda

12/14/2021, 1:03 PM
there is
LazyListScope.itemsIndexed
f

Florian

12/15/2021, 7:40 AM
@allan.conda bu I still don't kow how many items are displayed per row, right?
a

allan.conda

12/15/2021, 7:41 AM
Ah… Right, since it’s Adaptive.
To be honest that LazyGrid api kinda sucks 😅 and not flexible, though it’s still experimental to be fair. I think you can workaround by copying how they compute the columns for Adaptive
Copy code
BoxWithConstraints(
  modifier = modifier
) {
  val nColumns = maxOf((maxWidth / cells.minSize).toInt(), 1)
👍 1
c

Chris Sinco [G]

12/15/2021, 9:04 AM
@Andrey Kulikov might have some thoughts
a

Andrey Kulikov

12/15/2021, 2:59 PM
cc @Mihai Popa
6 Views