Fast scroll for Android RecyclerView
.
- This is a Kotlin rewrite of AndroidFastScroll with better popup position.
- Fully customizable: Override track, thumb, popup, animation and scrolling.
- Easy-to-use defaults: Predefined default style, Material Design 1 style and animation.
- Better popup position: Considers adjacent items instead of first visible item, enhancing the popup position during fast scrolling for a more intuitive user experience.
- Extensive view support: Out-of-box support for
RecyclerView
,ScrollView
,NestedScrollView
andWebView
, plus any view with aViewHelper
implementation. - Window insets friendly: Support setting a separate padding for scrollbar.
- Clean implementation: Decoupled touch handling, animation and scrolling logic.
preview.mp4
Default style | Material Design 1 style |
---|---|
- Kotlin:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// .. other stuff ..
maven("https://jitpack.io")
}
}
- Groovy:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
// .. other stuff ..
maven { url 'https://jitpack.io' }
}
}
- Kotlin:
dependencies {
// .. other stuff ..
implementation("com.github.StellarSand:AndroidFastScroll-kt:v1.0.8")
}
- Groovy:
dependencies {
// .. other stuff ..
implementation 'com.github.StellarSand:AndroidFastScroll-kt:v1.0.8'
}
- Simply create a
FastScroller
as follows:
FastScrollerBuilder(recyclerView).build()
- To show a popup, implement
PopupTextProvider
in yourRecyclerView.Adapter
.
class RvAdapter(
private val aListViewItems: ArrayList<RvData>
): RecyclerView.Adapter<RvAdapter.ListViewHolder>(), PopupTextProvider {
// .... other code ....
override fun getPopupText(view: View, position: Int): CharSequence {
return aListViewItems[position].title.substring(0, 1)
}
}
-
For more customization, please use the methods on
FastScrollerBuilder
. Namely:setViewHelper()
- allows providing a customViewHelper
to support more views.setPopupTextProvider()
- allows providing a customPopupTextProvider
if yourRecyclerView.Adapter
cannot implement that interface.setPadding()
- allows setting a custom padding for the scrollbar, instead of the padding of the view.setTrackDrawable()
andsetThumbDrawable()
- allow setting custom drawables for the scrollbar. Theandroid:state_pressed
state will be updated for them so you can use a selector. The track drawable needs to have an intrinsic width and the thumb drawable needs to have an intrinsic size, in order to allow proper touch event handling.setPopupStyle()
- allows customizing the popup view with a lambda that will receive the view.setAnimationHelper()
- allows providing a customAnimationHelper
to use an alternative scrollbar animation.disableScrollbarAutoHide()
- allows disabling the auto hide animation for scrollbar. This implies using aDefaultAnimationHelper
.useDefaultStyle()
anduseMd1Style()
- allow using the predefined styles, which sets the drawables and popup style.useDefaultStyle()
, as its name suggests, is the default style when aFastScrollerBuilder
is created.
-
The default
ViewHelper
implementation forRecyclerView
supports bothLinearLayoutManager
andGridLayoutManager
, but assumes that each item has the same height when calculating scroll, as there's no common way to deal with variable item height. If you know how to measure for scrolling in your specific case, you can provide your ownViewHelper
implementation and fast scroll will work correctly again. -
If you are using any
RecyclerView.ItemDecoration
that implementsonDrawOver()
, you might be interested inFixItemDecorationRecyclerView
which can fix the drawing order. -
If you are using any other library that makes use of
RecyclerView.OnItemTouchListener
(e.g.recyclerview-selection
), you might be interested inFixOnItemTouchListenerRecyclerView
which can correctly handle cancellations when dispatching touch events to listeners. You may also want to configure this library before others so that this library can take precedence in touch event handling.
This project is licensed under the terms of Apache v2.0 license.