Android快速滚动
16lz
2021-01-23
在开发过程中,使用listView假如有很多数据,要实现快速滚动的话,该怎么实现呢?其实很简单。只需要布局的xml文件里设置属性即可:
android:fastScrollEnabled="true"
android:focusable="true"
但是有时候会发现设置属性无效,滚动ListView并未出现滑块。原因是该属性生效有最小记录限制。当ListView记录能够在4屏以内显示(也就是说滚动4页)就不会出现滑块。可能是api设计者认为这么少的记录不需要快速滚动。
我的依据是android源代码,见FastScroller的常量声明:
// 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;
}
android:fastScrollEnabled="true"
android:focusable="true"
但是有时候会发现设置属性无效,滚动ListView并未出现滑块。原因是该属性生效有最小记录限制。当ListView记录能够在4屏以内显示(也就是说滚动4页)就不会出现滑块。可能是api设计者认为这么少的记录不需要快速滚动。
我的依据是android源代码,见FastScroller的常量声明:
// 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;
}
更多相关文章
- Android属性动画优化(更高效的使用属性动画)
- View类xml属性、方法
- TextView中ellipsize属性
- A06_RelativeLayout的属性设置
- animation的xml定义中的android:interpolator属性
- Android FrameLayout的android:foreground属性可以设置单击时的