Stay organized with collections
Save and categorize content based on your preferences.
CarouselSnapHelper
public
class
CarouselSnapHelper
extends SnapHelper
java.lang.Object
|
↳ |
androidx.recyclerview.widget.RecyclerView.OnFlingListener
|
|
↳ |
androidx.recyclerview.widget.SnapHelper
|
|
|
↳ |
com.google.android.material.carousel.CarouselSnapHelper
|
Implementation of the SnapHelper
that supports snapping items to the carousel keylines
according to the strategy.
Summary
Inherited methods |
From class
androidx.recyclerview.widget.SnapHelper
void
|
attachToRecyclerView(RecyclerView arg0)
|
abstract
int[]
|
calculateDistanceToFinalSnap(RecyclerView.LayoutManager arg0, View arg1)
|
int[]
|
calculateScrollDistance(int arg0, int arg1)
|
RecyclerView.SmoothScroller
|
createScroller(RecyclerView.LayoutManager arg0)
|
LinearSmoothScroller
|
createSnapScroller(RecyclerView.LayoutManager arg0)
|
abstract
View
|
findSnapView(RecyclerView.LayoutManager arg0)
|
abstract
int
|
findTargetSnapPosition(RecyclerView.LayoutManager arg0, int arg1, int arg2)
|
boolean
|
onFling(int arg0, int arg1)
|
|
From class
androidx.recyclerview.widget.RecyclerView.OnFlingListener
abstract
boolean
|
onFling(int arg0, int arg1)
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
CarouselSnapHelper
public CarouselSnapHelper ()
CarouselSnapHelper
public CarouselSnapHelper (boolean disableFling)
Parameters |
disableFling |
boolean |
Public methods
public void attachToRecyclerView (RecyclerView recyclerView)
Parameters |
recyclerView |
RecyclerView |
public int[] calculateDistanceToFinalSnap (RecyclerView.LayoutManager layoutManager,
View view)
Parameters |
layoutManager |
RecyclerView.LayoutManager |
view |
View |
public View findSnapView (RecyclerView.LayoutManager layoutManager)
Parameters |
layoutManager |
RecyclerView.LayoutManager |
public int findTargetSnapPosition (RecyclerView.LayoutManager layoutManager,
int velocityX,
int velocityY)
Parameters |
layoutManager |
RecyclerView.LayoutManager |
velocityX |
int |
velocityY |
int |
Protected methods
protected RecyclerView.SmoothScroller createScroller (RecyclerView.LayoutManager layoutManager)
This is mostly a copy of SnapHelper#createSnapScroller
with a slight adjustment to
call ERROR(/CarouselSnapHelper#calculateDistanceToSnap(LayoutManager, View, boolean))
(LayoutManager, View)}. We want to do a partial snap since the correct target keyline state may
not have updated yet since this gets called before the keylines shift.
Parameters |
layoutManager |
RecyclerView.LayoutManager |
Returns |
RecyclerView.SmoothScroller |
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# CarouselSnapHelper\n\nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Protected Methods](#promethods) \\| [Inherited Methods](#inhmethods) \n\nCarouselSnapHelper\n==================\n\n\n`\npublic\n\n\nclass\nCarouselSnapHelper\n`\n\n\n`\n\n\n`\n\n`\n\n\n`\n\n`\n\nextends SnapHelper\n\n\n`\n\n`\n\n\n`\n\n|---|---|---|---------------------------------------------------------|\n| java.lang.Object ||||\n| ↳ | androidx.recyclerview.widget.RecyclerView.OnFlingListener |||\n| | ↳ | androidx.recyclerview.widget.SnapHelper ||\n| | | ↳ | com.google.android.material.carousel.CarouselSnapHelper |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nImplementation of the [SnapHelper](/reference/androidx/recyclerview/widget/SnapHelper) that supports snapping items to the carousel keylines\naccording to the strategy.\n\nSummary\n-------\n\n| ### Public constructors ||\n|--------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[CarouselSnapHelper](/reference/com/google/android/material/carousel/CarouselSnapHelper#CarouselSnapHelper())`() ` |\n| ` `[CarouselSnapHelper](/reference/com/google/android/material/carousel/CarouselSnapHelper#CarouselSnapHelper(boolean))`(boolean disableFling) ` |\n\n| ### Public methods ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[attachToRecyclerView](/reference/com/google/android/material/carousel/CarouselSnapHelper#attachToRecyclerView(androidx.recyclerview.widget.RecyclerView))`(RecyclerView recyclerView) ` |\n| ` int[]` | ` `[calculateDistanceToFinalSnap](/reference/com/google/android/material/carousel/CarouselSnapHelper#calculateDistanceToFinalSnap(androidx.recyclerview.widget.RecyclerView.LayoutManager,%20android.view.View))`(RecyclerView.LayoutManager layoutManager, View view) ` |\n| ` View` | ` `[findSnapView](/reference/com/google/android/material/carousel/CarouselSnapHelper#findSnapView(androidx.recyclerview.widget.RecyclerView.LayoutManager))`(RecyclerView.LayoutManager layoutManager) ` |\n| ` int` | ` `[findTargetSnapPosition](/reference/com/google/android/material/carousel/CarouselSnapHelper#findTargetSnapPosition(androidx.recyclerview.widget.RecyclerView.LayoutManager,%20int,%20int))`(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) ` |\n\n| ### Protected methods ||\n|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` RecyclerView.SmoothScroller` | ` `[createScroller](/reference/com/google/android/material/carousel/CarouselSnapHelper#createScroller(androidx.recyclerview.widget.RecyclerView.LayoutManager))`(RecyclerView.LayoutManager layoutManager) ` This is mostly a copy of `SnapHelper#createSnapScroller` with a slight adjustment to call [ERROR(/CarouselSnapHelper#calculateDistanceToSnap(LayoutManager, View, boolean))](/) (LayoutManager, View)}. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` androidx.recyclerview.widget.SnapHelper ` |--------------------------------|---------------------------------------------------------------------------------| | ` void` | ` attachToRecyclerView(RecyclerView arg0) ` | | ` abstract int[]` | ` calculateDistanceToFinalSnap(RecyclerView.LayoutManager arg0, View arg1) ` | | ` int[]` | ` calculateScrollDistance(int arg0, int arg1) ` | | ` RecyclerView.SmoothScroller` | ` createScroller(RecyclerView.LayoutManager arg0) ` | | ` LinearSmoothScroller` | ` createSnapScroller(RecyclerView.LayoutManager arg0) ` | | ` abstract View` | ` findSnapView(RecyclerView.LayoutManager arg0) ` | | ` abstract int` | ` findTargetSnapPosition(RecyclerView.LayoutManager arg0, int arg1, int arg2) ` | | ` boolean` | ` onFling(int arg0, int arg1) ` | ||\n| From class ` androidx.recyclerview.widget.RecyclerView.OnFlingListener ` |---------------------|---------------------------------| | ` abstract boolean` | ` onFling(int arg0, int arg1) ` | ||\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic constructors\n-------------------\n\n### CarouselSnapHelper\n\n```\npublic CarouselSnapHelper ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### CarouselSnapHelper\n\n```\npublic CarouselSnapHelper (boolean disableFling)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|------------------|\n| `disableFling` | `boolean` \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### attachToRecyclerView\n\n```\npublic void attachToRecyclerView (RecyclerView recyclerView)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|-----------------------|\n| `recyclerView` | `RecyclerView` \u003cbr /\u003e |\n\n### calculateDistanceToFinalSnap\n\n```\npublic int[] calculateDistanceToFinalSnap (RecyclerView.LayoutManager layoutManager, \n View view)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------------|-------------------------------------|\n| `layoutManager` | `RecyclerView.LayoutManager` \u003cbr /\u003e |\n| `view` | `View` \u003cbr /\u003e |\n\n| Returns ||\n|---------|--------|\n| `int[]` | \u003cbr /\u003e |\n\n### findSnapView\n\n```\npublic View findSnapView (RecyclerView.LayoutManager layoutManager)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------------|-------------------------------------|\n| `layoutManager` | `RecyclerView.LayoutManager` \u003cbr /\u003e |\n\n| Returns ||\n|--------|--------|\n| `View` | \u003cbr /\u003e |\n\n### findTargetSnapPosition\n\n```\npublic int findTargetSnapPosition (RecyclerView.LayoutManager layoutManager, \n int velocityX, \n int velocityY)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------------|-------------------------------------|\n| `layoutManager` | `RecyclerView.LayoutManager` \u003cbr /\u003e |\n| `velocityX` | `int` \u003cbr /\u003e |\n| `velocityY` | `int` \u003cbr /\u003e |\n\n| Returns ||\n|-------|--------|\n| `int` | \u003cbr /\u003e |\n\nProtected methods\n-----------------\n\n### createScroller\n\n```\nprotected RecyclerView.SmoothScroller createScroller (RecyclerView.LayoutManager layoutManager)\n```\n\n\nThis is mostly a copy of `SnapHelper#createSnapScroller` with a slight adjustment to\ncall [ERROR(/CarouselSnapHelper#calculateDistanceToSnap(LayoutManager, View, boolean))](/)\n(LayoutManager, View)}. We want to do a partial snap since the correct target keyline state may\nnot have updated yet since this gets called before the keylines shift.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------------|-------------------------------------|\n| `layoutManager` | `RecyclerView.LayoutManager` \u003cbr /\u003e |\n\n| Returns ||\n|-------------------------------|--------|\n| `RecyclerView.SmoothScroller` | \u003cbr /\u003e |"]]