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

问题描述 投票:48回答:8

我列出了按月和年分隔的事件列表(2010年6月,2010年7月等)

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

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

android android-listview fastscroll
8个回答
98
投票

在ListActivity的onCreate方法中使用setFastScrollEnabled

getListView().setFastScrollEnabled(true);

65
投票

在xml中使用android:fastScrollEnabled

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

6
投票

请尝试以下方法

 <?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">

这是列表视图

 <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"
         />

4
投票

如果您希望能够自定义快速滚动条,就像选择自己的滚动图像一样,我建议使用此源:

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

基本上,listview适配器必须实现sectionindexer。如果您不想使事情复杂化并提供简单快速滚动列表的整个长度,则可以非常剥离此节索引器。

fastscroller的直接来源是:

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

将此视图放在listview周围(将listview嵌入xml布局文件中的此视图中)并在listview上设置android:fastScrollEnabled =“true”。

您可能还想查看以前的答案:Fast Scroll display problem with ListAdapter and SectionIndexer


1
投票

我想做一些类似于你想要达到的目标。我碰到了this post。这是一种在不使用标准Android AlphabetIndexer的情况下实现快速滚动的好方法,它需要一个你可能并不总是拥有的Cursor。

基本上,您必须在适配器中实现SectionIndexer接口。在您的情况下,您将在滚动时显示当前时段而不是当前字母。


0
投票

如果要显示按字母顺序排列的索引,可能需要检查一下:

https://github.com/andraskindler/quickscroll

这是我创建的一个库项目,因为我必须在最近的一些应用程序中使用这种滚动模式,所以我认为其他人可能会对它感兴趣。它相当容易使用,请参阅上面github链接中的自述文件。


0
投票

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

1)  <ListView
        ...
        android:fastScrollEnabled="true" />

2) mListView.setFastScrollEnabled(true);

0
投票

在布局文件中:

机器人:fastScrollEnabled = “真”

您可以通过编程方式启用快速滚动条:

getListView()setFastScrollEnabled(真)。

© www.soinside.com 2019 - 2024. All rights reserved.