animateScrollToItem

suspend fun animateScrollToItem(item: Int, animationSpec: AnimationSpec<Float> = spring())

Scroll animate to a given item. If the item is too far away from currentItem, Carousel will avoid composing all intermediate items by jumping to a nearer item before animating the scroll.

Please refer to the sample to learn how to use this API.

Parameters

item

the index of the item to scroll to with an animation

animationSpec

an AnimationSpec used to scroll between the items.

Samples

androidx.compose.material3.samples.HorizontalCenteredHeroCarouselSample