Detailed setting and example code of Android listview scroll bar

Detailed explanation of Android listview scroll bar settings

1. Properties of scroll bar

Sets whether the horizontal scroll bar is always displayed. Here, the tests with Scrollview and listview have no effect.

Sets whether the vertical scroll bar is always displayed. Here, the tests with Scrollview and listview have no effect.

Fade starts after n milliseconds is set, in milliseconds.

Sets the time, in milliseconds, when the scroll bar fades out (from presence to slow fading to disappearance). The scroll bar in Android 2.2 will disappear after scrolling, and then scroll out again. It will always be displayed in versions 1.5 and 1.6.

Sets the width of the scroll bar.

Set the style and position of the scroll bar. Setting values: insideoverlay, insideinside, outsideoverlay, outsideinside. There are not many effects here. The following is the comparison of outsideoverlay and outsideinset effects:

Set the drawable (such as color) of the horizontal scroll bar.

Set the drawable (e.g. color) of the vertical scroll bar

Set the color drawable (such as color) of the background (track) of the horizontal scroll bar

Set the drawable of the background (track) of the vertical scroll bar. Note that setting the color value directly, such as "Android: color / white", will produce a very ugly effect. You don't even understand this attribute. Here, see RES / drawable / scrollbar in apidemos_ vertical_ Thumb.xml and scrollbar_ vertical_ Track.xml, set the code as:

Set the scroll bar display. None, horizontal, vertical. See the following code to demonstrate using this property to have a scroll bar in EditText. However, other containers, such as LinearLayout, are set but have no effect

Set whether to display as a slider (but sometimes it is found that the setting property is invalid, and there is no slider when scrolling the listview. The reason is that there is a minimum record limit for the property to take effect. When the listview records can be displayed within 4 screens (that is, scrolling 4 pages), there will be no slider. It may be that the API designer thinks that so few records do not need to scroll quickly.)

2. Problems and precautions

Note: it may be due to adaptation. You may not see much effect if you set scrollbarsize, but you can see it if you configure scrollbarthumbvertical

3. How to modify the style of slider

Based on the Android source code, see the constant declaration of fastscroller:

The listview and its super tired abslistview are viewed throughout, and the setting interface of custom pictures is not found. It seems that there is no intention for developers to change. But the user asked us to customize this picture. That can only be done by extraordinary means.

After analysis, it is found that the picture is a member of listview superclass abslistview and a member of mfastscroller object mthumbdrawable. Here mthumbdrawable is of type drawable. Mfastscroller is a fastscroller type, which is troublesome. The class declaration has no modifier, that is, default (package), and can only be called by classes in the package.

Therefore, writing reflection code is a little more troublesome:

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>