Scrolling Recipes¶
Scrolling to specific positions¶
To scroll to a specific position, use the selection methods from DpadRecyclerView
:
setSelectedPosition
- to scroll immediately to a given positionsetSelectedPositionSmooth
- to smooth scroll to a given position
If you're interested in triggering a callback once the selection is applied, you can do the following:
Disabling smooth scrolling¶
DpadRecyclerView
allows disabling smooth scrolling on focus changes with:
This will make DpadRecyclerView
scroll immediately without any animation to the new focused view.
Changing smooth scrolling behavior¶
The code below changes the default interpolator used for smooth scrolling to a linear interpolator:
To slow down the smooth scrolling speed, check setSmoothScrollSpeedFactor
:
The code above will make smooth scrolling twice slower.
Limiting number of pending alignments¶
Sometimes you might want to prevent the user from scrolling past too many items.
You can specify the number of max pending alignments with: setSmoothScrollMaxPendingAlignments
:
The code above translates to this behavior:
In the right scenario, there's just one next focusable view since the focused view still isn't aligned to the keyline.
Enabling layout during scrolling events¶
If you want to enable layout changes while DpadRecyclerView
is still scrolling, use:
Long text scrolling¶
In some cases, you might need to show pages with text that should be scrollable (e.g terms & conditions).
For this use case, you can use DpadScroller
:
DpadScroller
will scroll the page for you on key event presses without any alignment so that the user can read the entire content