This is a modification of this question. I have an isometric grid of images and curious - is it possible to scroll it in free ways (diagonals included). Currently I have this code and it's possible to scroll 2D:
val scrollStateHorizontal = rememberScrollState()
val scrollStateVertical = rememberScrollState()
Box(
modifier = Modifier
.horizontalScroll(scrollStateHorizontal)
.verticalScroll(scrollStateVertical)
) {
for (i in 0..8) {
for (j in 0..7) {
val start = (y % 2 * 0.5 + x) * width
val top = i * height * 0.5
Image(modifier = Modifier.padding(start = start.dp, top = top.dp), painter = ...)
}
}
}
What is interesting:
- Can I scroll diagonally?
- How can I optimize it (memory consumption, etc.)? Maybe I should use
LazyHorizontalGrid
includingLazyVerticalGrid
/LazyColumn
/LazyRow
?
It seems, LazyHorizontalGrid
can't be modified simply adding Modifier.verticalScroll
. And it has a lag for first few seconds of scrolling (maybe for caching items) while simple Box
scrolling acts smoothly from the start.