如何在android中使用快速滚动?

我有一个按月份和年份分列的事件列表(2010年6月,2010年7月等)

我想启用快速滚动,因为列表很长。

如何在Android的ListViews上启用快速滚动?

在ListActivity的onCreate方法中,使用setFastScrollEnabled :

 getListView().setFastScrollEnabled(true); 

在你的xml中使用android:fastScrollEnabled

 <ListView android:id="@+id/listview_files" ... android:fastScrollEnabled="true" > </ListView> 

尝试以下

  <?xml version="1.0" encoding="utf-8"?> <resources> <style name="listviewfastscrollstyle" parent="android:Theme"> <item name="android:fastScrollTrackDrawable">@drawable/listselector</item> <item name="android:fastScrollThumbDrawable">@drawable/listselector</item> </style> </resources> 

在你的Manifest中设置这样的样式:

 <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme"> 

这是listview

  <ExpandableListView android:id="@android:id/list1" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:drawSelectorOnTop="false" android:fastScrollAlwaysVisible="true" android:fastScrollEnabled="true" /> 

如果您希望能够自定义快速滚动条,例如select自己的滚动条图像,我build议使用以下来源:

https://github.com/nolanlawson/CustomFastScrollViewDemo/

基本上,你的listview适配器将不得不实现一个sectionindexer。 这部分索引器可以非常剥离,如果你不想复杂的事情,并提供简单的快速滚动,但整个列表的长度。

fastscroller的直接来源是这里:

https://github.com/nolanlawson/CustomFastScrollViewDemo/blob/master/src/com/nolanlawson/customfastscrollviewdemo/CustomFastScrollView.java

将这个视图放置在你的列表视图中(在你的xml布局文件中将你的列表视图嵌套在这个视图中),并在你的列表视图中设置android:fastScrollEnabled =“true”。

您可能还想查看以前的答案: 使用ListAdapter和SectionIndexer快速滚动显示问题

我想做一些类似于你想达到的事情。 我撞到了这个post 。 这是一个很好的方式来实现快速滚动,而不使用标准的Android AlphabetIndexer,这需要一个你可能并不总是有光标。

基本上,你将不得不在你的适配器中实现SectionIndexer接口。 在你的情况,而不是当前的信件,你会显示当前的期间,你滚动。

如果你想显示字母索引,你可能想检查一下:

https://github.com/andraskindler/quickscroll

这是我创build的一个库项目,因为我不得不在最近的几个应用程序中使用这个滚动模式,所以我想其他人可能会对它感兴趣。 这很容易使用,请参阅上面的github链接的自述文件。

在xml中定义fastScrollEnabled,或者在需要时在运行时设置它。

 1) <ListView ... android:fastScrollEnabled="true" /> 2) mListView.setFastScrollEnabled(true); 

在布局文件中:

机器人:fastScrollEnabled = “真”

您可以编程启用快速滚动条:

getListView()setFastScrollEnabled(真)。

Interesting Posts