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.
Asked
Active
Viewed 2,490 times
4

Soheil Setayeshi
- 2,343
- 2
- 31
- 43
1 Answers
2
Try overriding onInterceptTouchEvent()
of your children like this:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(!isAtTop && !isAtBottom){
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onInterceptTouchEvent(ev);
}
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
}

thaussma
- 9,756
- 5
- 44
- 46
-
Thank , I think I should work on it's scroll position but thank you for your hints; – Soheil Setayeshi Jul 18 '13 at 10:36
-
The scrollbar position depends on the scroll position, so it really doesn't matter. – thaussma Jul 18 '13 at 10:49