Reputation: 545
I have a lazy list that I am animating scroll to Item when clicking on a button.
onClick = {
scope.launch {
lazyListState.animateScrollToItem(selectedIndex)
}
}
Why is it that the animateScrollToItem is SO fast? Can I slow it down a little? I am not seeing anywhere I can add a animationSpec, and with animateScrollBy() I would need to pass in a float rather than an index - which I do not want.
Upvotes: 16
Views: 6617
Reputation: 91
That's the only possible way for now. animateScrollBy()
is not that bad by the way, all you need is to know the size of the lazy container item.
val itemSize = 50.dp
val density = LocalDensity.current
val itemSizePx = with(density) { itemSize.toPx() }
val itemsScrollCount = 150
coroutineScope.launch {
lazyListState.animateScrollBy(
value = itemSizePx * itemsScrollCount
animationSpec = tween(durationMillis = 5000)
)
}
Upvotes: 7