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


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


项目中曾经就出现过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(安卓)通知栏Notification的整合 全面学习 (一个DEMO让你
  2. android调用隐藏的网络信息设置菜单实现
  3. Android之TextView属性列表
  4. android:padding和android:margin的区别
  5. Android中TextView属性
  6. android 各种控件颜色值的设置(使用Drawable,Color)
  7. android和ios的系统特性区别
  8. Android(安卓)- GridView,自定义开关控件,状态选择器selector,自定
  9. Android(安卓)textview 只显示一行,多余部分显示.....

随机推荐

  1. 关于android的des算法代码
  2. Android设置Dialog设置圆角
  3. Fragment传值到Fragment的操作步骤
  4. android WiFi 开关代码
  5. android中的webview进度条
  6. MySQL DISTINCT 的基本实现原理详解
  7. MySql 8.0.16版本安装提示已经不使用“UT
  8. mysql 8.0.16 winx64及Linux修改root用户
  9. Mysql解决数据库N+1查询问题
  10. MySQL全文索引实现简单版搜索引擎实例代