Android 滚动条

发布时间:2020-06-19 03:24:51 作者:mama100Tech
来源:网络 阅读:747

小小滚动条,设计还是挺复杂。


其中有两种类型的滚动条,一条是普通的滑动时的滚动条,一种是快速滚动条


项目中曾经就出现过XML定义了 android:scrollbars="none" 但是滑动时,还是会出现

滚动条,其中是因为设置了快速滚动条的原因 android:fastScrollEnabled="true",而默认android:fastScrollEnabled是false的


关于快速滚动条还有最小页数设置,见FashScroller源码,当滚动的页数在4页之内时,是不会出现快速滚动条的


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

 以及:

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


还有就是有时可能要自定义滚动条的图片

XML定义如下:

android:scrollbarThumbVertical

android:scrollbarThumbHorizontal

代码设置如下:

//修改快速滚动条图片
        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();
                }
//修改竖向滚动条图片
                
                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();
                }




推荐阅读:
  1. Android中如何使用GridView 属性
  2. android的ListView的分页加载

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android 滚动条 快速 自定义 roi

上一篇:Juniper NetScreen 基于源NAT转换

下一篇:Duilib中的消息泵和虚拟窗口

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》