You can create your own custom scrollbar and tie it with recycler view.
Following is extension method for recycler view to handle the above made scrollbar
fun RecyclerView.handleScroll(itemScrollerBinding: ItemScrollerBinding) {
post {
val parentWidth = itemScrollerBinding.parent.width
val layoutParams = itemScrollerBinding.progress.layoutParams
val initialX = itemScrollerBinding.progress.x
layoutManager?.let {
val totalWidth = this.computeHorizontalScrollRange()
val visibleWidth = this.computeHorizontalScrollExtent()
val percent =
visibleWidth.toFloat() / totalWidth.toFloat()
layoutParams.width = (parentWidth * percent).toInt()
itemScrollerBinding.progress.layoutParams = layoutParams
addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrolled(
recyclerView: RecyclerView,
dx: Int,
dy: Int,
) {
super.onScrolled(recyclerView, dx, dy)
val scrolledWidth =
this@handleScroll.computeHorizontalScrollOffset()
val updatedVisibleWidthRecyclerView =
visibleWidth + scrolledWidth
val scrolledWidthScroller =
((parentWidth.toFloat() / totalWidth) * scrolledWidth)
itemScrollerBinding.progress.x =
initialX + scrolledWidthScroller
}
})
}
}
}
Following is xml code for ItemScrollerBinding
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="@dimen/size_48"
android:layout_height="@dimen/size_6"
android:background="@drawable/bg_scroller_background">
<LinearLayout
android:id="@+id/progress"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@drawable/bg_scroller"
android:orientation="horizontal" />
</FrameLayout>
You can place this below the recycler view and center it.