Fast scrolling is one of the oldest features provided by Android and other OS(s) as well. This feature helps you to scroll easily in a list which can be huge in size and makes it pretty fast and simple to search for a particular element.
Implementing this is very easy using a library named as Recycler-Fast-Scroll provided by FutureMind.
To get the fast scrolling. First, you need to add the dependency to your module level build.gradle.
1 |
compile 'com.futuremind.recyclerfastscroll:fastscroll:0.2.5' |
After this, you need to add the scrolling layout in the view and for that open the XML file of your activity or fragment and add the following code
1 2 3 4 5 6 7 |
<com.futuremind.recyclerviewfastscroll.FastScroller android:id="@+id/fast_scroller" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" /> |
This will provide you the bar which will be used to scroll through the recyclerview elements and it is customizable too.
Now, you need to attach this fast_scroller to the recyclerview and for that, you can follow the below code segment
1 |
your_fast_scroller.setRecyclerView(your_recyclerview); |
And to get the bubble which will display the character you need implement SectionTitleProvider in the recyclerview adapter and override its getSectionTitle function.
1 2 3 4 5 6 7 8 9 10 |
public class MyAdapter ... implements SectionTitleProvider{ ... @Override public String getSectionTitle(int position) { //this String will be shown in a bubble for specified position return getItem(position).substring(0, 1); } } |
That’s all, You can enjoy your fast scrolling feature wherever you want.
Thank you very much, this is Vedesh Kumar signing off.