Use listview fastscroller to display the default slider and custom slider image:
It is easy to set the quick rolling attribute. You only need to set the attribute in the XML file of the layout:
<Listview Android: Id = "@ + ID/listview" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"Android: fastscrollenabled = "true"
Android: focusable = "true"/>
However, sometimes you will find that the setting property is invalid and the slider does not appear in the scrolling listview. The reason is that this attribute has a minimum record limit. When the listview record can be displayed within 4 screens (that is, four pages are rolled), no slider will appear. It may be that API designers think that so few records do not need to be quickly rolled.
My basis is the android source code. See the constant declaration of fastscroller:
// Minimum number of pages to justify showing a fast scroll thumb
Private Static int min_pages = 4;
And:
// Are there enough pages to require fast scroll? Recompute only if total count changes
If (mitemcount! = Totalitemcount & visibleitemcount> 0 ){
Mitemcount = totalitemcount;
Mlonglist = mitemcount/visibleitemcount> = min_pages;
}
After reading the listview and its over-tired abslistview, none of them found the interface for setting custom images. It seems that the developer has no intention of making changes. However, you need to customize the image. It can only be used with great means.
After analysis, it is found that the image is a member of the mfastscroler object of the listview super class abslistview, and the member of the mfastscroler object is mshumbdrawable. In this example, the value of the mthumbdrawable type is drawable. Mfastscroller is the fastscroller type. This type is troublesome. The class declaration does not have modifier, that is, default (Package). It can only be called by classes in the package.
Therefore, writing reflection code is a little troublesome:
Try {
Field F = abslistview. Class. getdeclaredfield ("mfastscroller ");
F. setaccessible (true );
Object o = f. Get (listview );
F = f. GetType (). getdeclaredfield ("mthumbdrawable ");
F. setaccessible (true );
Drawable = (drawable) F. Get (O );
Drawable = getresources (). getdrawable (R. drawable. Icon );
F. Set (O, drawable );
Toast. maketext (this, F. GetType (). getname (), 1000). Show ();
} Catch (exception e ){
Throw new runtimeexception (E );
}
In this way, you can change the default slider image.