我现在用这个新的 -
https://github.com/L4Digital/FastScroll
下面是我以前的。
我在 Android Studio
中使用过 FutureMind 的 fastscroller
https://github.com/FutureMind/recycler-fast-scroll
用法
1) 通过添加编译所需的依赖项
编译'com.futuremind.recyclerfastscroll:fastscroll:0.2.4'
2) 编辑布局文件以添加 FastScroller
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.futuremind.recyclerviewfastscroll.FastScroller
android:id="@+id/fastscroll"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
3) 在 Activity/Fragment 中,将 fastScroller 与您的回收站视图关联
recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
fastScroller = (FastScroller) findViewById(R.id.fastscroll);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
//has to be called AFTER RecyclerView.setAdapter()
fastScroller.setRecyclerView(recyclerView);
4) 在您的 RecyclerView.Adapter 中实现 SectionTitleProvider 以在 Bubble 上显示内容
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);
}
}