当用户滚动列表视图时,我想显示/隐藏视图。
如何检测过度滚动?有听众吗?我已经尝试过OnScrollListener
,但它只通知onScrollStateChanged
和onScroll
当用户滚动列表视图时,我想显示/隐藏视图。
如何检测过度滚动?有听众吗?我已经尝试过OnScrollListener
,但它只通知onScrollStateChanged
和onScroll
您可以覆盖方法onOverScrolled,因为它respond to the results of an over-scroll operation.
只是更完整的答案
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
View view = (View) getChildAt(getChildCount()-1);
int diff = (view.getBottom()-(getHeight()+getScrollY()));
if(diff==0) {
//overscroll on bottom
} else {
//overscroll on top
}
}
scrollY = 非零和clampedY = true --> OverScroll 状态发生在从下到上滚动时
scrollY = 零和clampedY = true --> OverScroll 状态发生在从上到下滚动时
所以
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
if(clampedY){
if(scrollY==0){
//over Scroll at top
}else {
//over Scroll at Bottom
}
}
}