在自定义的ListView onInterceptTouchEvent [英] Custom onInterceptTouchEvent in ListView
问题描述
我如何能实现一个自定义的 onInterceptTouchEvent()
在的ListView
,让滚动优先考虑儿童的在的ListView
,并尽快为他们做了他们的滚动,还给了的ListView
?我想对内部的意见为主。
How can I implement a custom onInterceptTouchEvent()
in a ListView
that give the scrolling priority to the child's of the ListView
and as soon as they did their scrolling , give it back to the ListView
? I want to give priority to the inner views.
推荐答案
尝试重写 onInterceptTouchEvent()
您的孩子是这样的:
Try overriding onInterceptTouchEvent()
of your children like this:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(!isAtTop && !isAtBottom){
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
在 onInterceptTouchEvent()
计算,如果在ListView已经完全滚动到顶部或底部。如果它是介于两者之间则要求家长不要拦截触摸。
In onInterceptTouchEvent()
calculate if the ListView has scrolled totally to the top or bottom. If it is somewhere in between then ask the parent to not intercept touches.
要检查顶部或底部的尝试:
To check for top or bottom try:
int scrollRange = computeVerticalScrollRange();
int scrollOffset = computeVerticalScrollOffset();
int scrollExtend = computeVerticalScrollExtent();
if(scrollOffset == 0){
//AtTop
}else if(scrollRange == scrollOffset + scrollExtend){
//AtBottom
}
这篇关于在自定义的ListView onInterceptTouchEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!