如何使用RecyclerView显示沿滚动条移动的文本? [英] How to show text that moves along scrollbar using RecyclerView?
问题描述
我正在使用Recylerview,并且想要显示这样的列表 https://i.stack .imgur.com/kMh1q.png
我试图按如下所示在xml中启用fastScroll,但是它只能更改Recyclerview的缩略图和轨迹,并且无法按预期显示文本.
I'm using Recylerview and want to show list like this https://i.stack.imgur.com/kMh1q.png
I've tried to enable fastScroll in xml as below however it only can change thumb and track of Recyclerview and can't show the text as I expected.
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
app:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
app:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
app:fastScrollVerticalTrackDrawable="@drawable/line_drawable"/>
我正在Recyclerview中寻找类似于fastScrollTextColor
和fastScrollPreviewBackgroundRight
的属性,以沿滚动条显示文本,如本例所示 http://androidopentutorials.com/android-listview-fastscroll/,但是RecyclerView似乎不支持这些内容
在该示例中,使用ListView代替,并且可以将这些属性声明为ListView的样式
I'm looking for attributes similar to fastScrollTextColor
and fastScrollPreviewBackgroundRight
in Recyclerview to shows text along scrollbar like in this example http://androidopentutorials.com/android-listview-fastscroll/ but it seem that RecyclerView doesn't support those
In that example uses ListView instead and these attributes can be declare in as styles of ListView
<style name="FastScrollStyle" parent="AppBaseTheme">
<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
<item name="android:fastScrollOverlayPosition">atThumb</item>
<item name="android:fastScrollTextColor">@color/apptheme_color</item>
<item name="android:fastScrollTrackDrawable">@drawable/fastscroll_thumb_pressed_holo</item>
<item name="android:fastScrollPreviewBackgroundRight">@drawable/bg_default_focused_holo_light</item>
</style>
任何人都可以使用RecyclerView来帮助我吗?谢谢!
Anyone can help me do so with RecyclerView? Thanks!
推荐答案
github上有一个用于此目的的库: https://github.com/viethoa/recyclerview-alphabet-fast-scroller- android
There's a library on github made for this purpose: https://github.com/viethoa/recyclerview-alphabet-fast-scroller-android
我还找到了一个实现它的项目: https://github.com/codexpedia/android_fast_scroll_with_alphabet/tree/master/fast_scroll_with_alphabet2
And I also found a project implementing it: https://github.com/codexpedia/android_fast_scroll_with_alphabet/tree/master/fast_scroll_with_alphabet2
这篇关于如何使用RecyclerView显示沿滚动条移动的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!