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

Yves Kalume

04/20/2022, 12:41 PM
Hi, how can i get LazyColumn scroll percentage ?
j

Jhonatan Sabadi

04/20/2022, 12:50 PM
you have
firstVisibleItemIndex
that you can calculate de percentage with this information. Ex.: List with 10 items, the first visible is the third item, so your scroll percentage is 30%
1
f

Filip Wiesner

04/20/2022, 1:00 PM
Just be aware that this will be "item scroll" percentage and not really a "content scroll" percentage. For the latter you would have to calculate height of all the items which would defeat the purpose of lazy layout 😕 Also I think that by using this method you would never get a 100% scroll, right? 🤔
n

nitrog42

04/20/2022, 1:04 PM
"what about mixing with lastVisibleItemIndex" but it doesn't exists 😄
j

Jhonatan Sabadi

04/20/2022, 1:05 PM
Agree. Maybe will not be exactly what you want, maybe you have to calculate height, like @Filip Wiesner said.
n

nitrog42

04/20/2022, 1:07 PM
you can use
layoutInfo.visibleItemsInfo
to get all the visible items displayed on screen, maybe it can help to extrapolate an approximate scroll position, because I also don't think you should break the lazylist principle
f

Filip Wiesner

04/20/2022, 1:10 PM
Yeah, I didn't mean it like you should measure your items. I was just pointing out that Jhonatans answer may not be what you are looking for. I don't think there is a solution for this. All you can do is approximate the scroll position like nitrog42 suggests.
1
23 Views