Android scroll bar

Source: Internet
Author: User

Small scroll bar, the design is quite complicated.


There are two types of scroll bars, one is the normal sliding scroll bar, one is the fast scroll bar


There have been XML definitions of android:scrollbars= "None" in the project, but when you swipe, it will still appear

Scroll bar, where the fast scroll bar is set for the reason Android:fastscrollenabled= "true", and the default android:fastscrollenabled is False


About the Fast scroll bar also has the minimum number of pages set, see Fashscroller Source code, when the number of pages scrolled within 4 pages, there is no quick scroll bar


Minimum number of pages to justify showing a fast scroll thumb
private static int min_pages = 4;

And:

Is 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;
}


And there's the picture that sometimes you might want to customize the scroll bar

The XML is defined as follows:

Android:scrollbarthumbvertical

Android:scrollbarthumbhorizontal

The code is set up as follows:

//Modify the Quick scroll bar picture
try {
Field f = AbsListView.class.getDeclaredField ("Mfastscroller");
f.setaccessible (true);
Object o = F.get (this);
f = F.gettype (). Getdeclaredfield ("mthumbdrawable");
f.setaccessible (true);
drawable drawable = (drawable) f.get (o);
drawable = Getresources (). getdrawable (R.drawable.icon);
F.set (o, drawable);
} catch (Exception e) {
e.printstacktrace ();
                }
//Modify the vertical scroll bar picture
                
try {
Field f = View.class.getDeclaredField ("Mscrollcache");
f.setaccessible (true);
Object Scrollabilitycache = F.get (this);
f = F.gettype (). Getdeclaredfield ("ScrollBar");
f.setaccessible (true);
Object scrollbardrawable = F.get (Scrollabilitycache);
f = F.gettype (). Getdeclaredfield ("Mverticalthumb");
f.setaccessible (true);
drawable drawable = (drawable) f.get (scrollbardrawable);
drawable = Getresources (). getdrawable (r.drawable.rating_progress);
F.set (scrollbardrawable, drawable);
} catch (Exception e) {
e.printstacktrace ();
                }




This article is from the "Mom 100 Development Team" blog, please be sure to keep this source http://mama100tech.blog.51cto.com/8943983/1708721

Android scroll bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.