You can display a button to let a user snap scroll to a specific point in a list, saving time and increasing user engagement.
Version compatibility
This implementation requires that your project minSDK be set to API level 21 or higher.
Dependencies
Create a button to enable snap scrolling
Use the following code to create a button for smooth snap scrolling in a vertical lazy list with 10 items:
Key points about the code
- Uses the
listState
object to remember the scroll state ofLazyColumn
to the selected position. - Launches a coroutine to call
listState.animateScrollToItem
, which scrolls to the indexed item while animating the scrolling action.
Results
![A vertically scrolling list with an active button](https://developer.android.com/static/quick-guides/content/snap-scroll.gif?authuser=8)
Parent collections
![](https://developer.android.com/static/images/quick-guides/collection-illustration.png?authuser=8)
Display a list or grid
Lists and grids allow your app to display collections in a
visually pleasing form that's easy for users to consume.
![](https://developer.android.com/static/images/quick-guides/collection-illustration.png?authuser=8)
Display interactive components
Learn how composable functions can enable you to easily
create beautiful UI components based on the Material Design design
system.
![](https://developer.android.com/static/images/quick-guides/collection-illustration.png?authuser=8)
Compose basics (video collection)
This series of videos introduces various Compose APIs,
quickly showing you what’s available and how to use them.
Have questions or feedback
Go to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts.