Android list code to enable fast scrolling in the source code of the Android platform

In android, setFastScrollEnabled(true);used for fast <scrolling ListView.

This fast scrolling does not work when in ListViewfewer items. I read it somewhere that fast scrolling in android only works when the total list height is 4 times or more than the list view height. I spent hours trying to find it in the source code of the framework, but I can't find it.

Can someone tell me to place it in the source code of the Android framework, where this condition disables fast scrolling when there are fewer elements in the ListView.

+5
source share
2 answers

Yes, of course, here is the link:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/FastScroller.java

224-227. , , :

private static int MIN_PAGES = 4;

... , . FastScroller . , - , condidion Android:

//pseudocode
int numberOfPages = listView.itemsCount / listView.visibleItemsCount;
if(numberOfPages > yourValue)
    listView.setFastScrollEnabled(true);
else
    listView.setFastScrollEnabled(false);

, yourValue 4. , .

EDIT:

: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/widget/FastScroller.java/

: 444-447:)

- :

try {
Field scrollerField = AbsListView.class.getDeclaredField("mFastScroller");    //java.lang.reflect.Field
scrollerField.setAccessible(true);
FastScroller instance = scrollerField.get(listViewInstance);

Field minPagesField = instance.getClass().getDeclaredField("MIN_PAGES");
minPagesField.setAccessible(true);
minPagesField.set(instance, yourValue);
} catch (Exception e) {
Log.d("Error", "Could not get fast scroller");
}

, , .

+8

android:fastScrollAlwaysVisible="true"

xml

0

All Articles