android – 在ListView中自定义onInterceptTouchEvent
作者:互联网
如何在ListView中实现自定义onInterceptTouchEvent(),为ListView的子项提供滚动优先级,并在滚动后立即将其返回给ListView?我想优先考虑内心观点.
解决方法:
尝试覆盖你孩子的onInterceptTouchEvent(),如下所示:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(!isAtTop && !isAtBottom){
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
在onInterceptTouchEvent()中计算ListView是否完全滚动到顶部或底部.如果它介于两者之间,则要求父母不要拦截触摸.
要检查顶部或底部尝试:
int scrollRange = computeVerticalScrollRange();
int scrollOffset = computeVerticalScrollOffset();
int scrollExtend = computeVerticalScrollExtent();
if(scrollOffset == 0){
//AtTop
}else if(scrollRange == scrollOffset + scrollExtend){
//AtBottom
}
标签:android,android-listview,touch-event,interception 来源: https://codeday.me/bug/20190703/1368910.html