前几日在某机型上线上出现了一个与RecyclerView
上划下滑相关的BUG
。
源码解读
看了会儿RecyclerView
的canScrollVertically(int direction)
函数:
/**
* Check if this view can be scrolled vertically in a certain direction.
*
* @param direction Negative to check scrolling up, positive to check scrolling down.
* @return true if this view can be scrolled in the specified direction, false otherwise.
*/
public boolean canScrollVertically(int direction) {
final int offset = computeVerticalScrollOffset();
final int range = computeVerticalScrollRange() - computeVerticalScrollExtent();
if (range == 0) return false;
if (direction < 0) {
return offset > 0;
} else {
return offset < range - 1;
}
}
注释:入参direction
为负数时检测向上滑(手势由下往上,getScrollY()