Hi everyone! I want to have a layout which scrolls...
# compose
r
Hi everyone! I want to have a layout which scrolls both ways. So I tried using
Box
with horizontal scroll and a
LazyVerticalGrid
. This gives me
java.lang.IllegalArgumentException: LazyVerticalGrid's width should be bound by parent.
Can you please help me with the right way to go about this? Example code:
Copy code
Box(modifier = modifier.horizontalScroll(rememberScrollState())) {
        LazyVerticalGrid(
            //modifier = Modifier,
            columns = GridCells.Fixed(12)
        ) {
            items(20) {
                Box(modifier = Modifier.width(60.dp).height(20.dp).padding(8.dp).background(Color.Red))
            }
        }
    }
s
r
something like this! But only horizontal/vertical scroll
s
You can't have a lazy grid which doesn't know how wide it should be, as the error message suggests. What do you want to achieve exactly?
r
I want to achieve the ui in the video. I have achieved it using the following code:
Copy code
BoxWithConstraints (modifier = Modifier.fillMaxSize().horizontalScroll(rememberScrollState())) {
        LazyVerticalGrid(
            modifier = Modifier.fillMaxHeight().width(constraints.minWidth.dp),
            columns = GridCells.Fixed(12)
        ) {
            items(400) {
                Box(modifier = Modifier.width(80.dp).height(80.dp).padding(8.dp).background(Color.Red))
            }
        }
    }