2012-02-21 71 views
45

我有一個是通過月份和年份分隔的事件列表(2010年6月,2010年7月等)如何在android中使用快速滾動?

我想啓用快速滾動,因爲名單是很長的。

如何啓用在Android的ListViews快速滾動?

回答

95

在ListActivity使用setFastScrollEnabled的onCreate方法:

getListView().setFastScrollEnabled(true); 
+42

注意:只有當listview總高度比listview的可見高度大4倍或更多時纔會顯示。 – 2012-03-28 03:20:43

+1

@mice:是否有關於您評論的文檔? – 2012-12-20 05:36:57

+2

可能沒有記錄,該條件在源代碼中找到。 – 2012-12-20 09:01:51

60

使用android:fastScrollEnabled在你的XML:

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

如果你希望能夠自定義您的快速滾動,例如選擇自己的滾動形象出現,我建議使用此來源:

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

基本上,你的ListView適配器將不得不實施sectionindexer。本節索引器,如果你不想要的東西複雜化,並提供簡單的fastscrolling好像列表的整個長度上非常精簡。

的直接來源爲fastscroller是在這裏:

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

將在你的列表視圖(鳥巢您的ListView這一觀點在你的XML佈局文件中),並設置Android的這一觀點:fastScrollEnabled =「真」在你的listview上。

你可能也想看看以前的答案:Fast Scroll display problem with ListAdapter and SectionIndexer

0

如果你想顯示字母索引,你可能要檢查了這一點:

https://github.com/andraskindler/quickscroll

這是一個圖書館項目我創建的,因爲我曾在最近的一些應用程序來使用這個滾動圖形,所以我想其他人可能也感興趣。這很容易使用,請參閱上面的github鏈接中的自述文件。

5

請嘗試以下

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

在你的清單中設置的風格是這樣的:

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

好吧我可以做日期快速滾動,我的意思是,當執行快速滾動時,我可以顯示記錄的日期,如通話歷史中的一個 – Rakshi 2013-05-15 11:24:17

1

我想要做類似的東西給你想實現。我撞到this post。它是實現快速滾動,而無需使用標準的Android AlphabetIndexer,這需要一個遊標你可能並不總是有一個偉大的方式。

基本上,你就必須實現您的適配器SectionIndexer接口。在你的情況下,而不是當前的信件,你會滾動顯示當前的時間段。

0

要麼在您的xml中定義fastScrollEnabled,要麼在需要時將其設置爲運行時。

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

2) mListView.setFastScrollEnabled(true); 
0

在佈局文件:

機器人:fastScrollEnabled = 「真」

您可以通過編程啓用快速滾動條:

getListView()setFastScrollEnabled(真正);

相關問題