3

I want my LazyColumn to show items in the list from the middle so I can scroll up or down. I used rememberLazyListState but it has some delay and I don't want the scrolling action to happen in the UI.

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
Mehranjp73
  • 341
  • 6
  • 20

1 Answers1

3
val scrollState = rememberLazyListState(initialFirstVisibleItemIndex = 50)
val scrollState = rememberLazyListState(initialFirstVisibleItemScrollOffset = 3700)

You can use anyone of the parameter to start from a default position if you have 100 items in the list you could set initialFirstVisibleItemIndex = 50 so it starts from middle also you can set the offset but just use any one of them.

It works for me without any delay

Jack
  • 788
  • 3
  • 13
  • It works for the first list but when I update the list, it doesn't work anymore. – Mehranjp73 Sep 14 '21 at 09:21
  • Ok what do you mean by updating the list? Do you want to snap to the middle every time an item is added or removed? – Richard Onslow Roper Sep 14 '21 at 09:56
  • @Mehranjp73 that's what the parameter name also says it's `initial` but why would you want the list to be always at middle, what you could do is call `scrollToItem` method every time list is updated. – Jack Sep 14 '21 at 11:02
  • It scrolls using scrollToItem but it shows the moving of the list. – Mehranjp73 Sep 14 '21 at 15:57