Custom onInterceptTouchEvent in ListView

How can I implement a custom onInterceptTouchEvent() in a ListView that gives scroll priority to a child of a ListView , and as soon as they scroll, return it to a ListView ? I want to give priority to internal representations.

+4
source share
1 answer

Try overriding your kids onInterceptTouchEvent() as follows:

 @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if(!isAtTop && !isAtBottom){ getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } 

In onInterceptTouchEvent() calculate whether the ListView scrolls completely at the top or bottom. If it is somewhere in the middle, ask the parent not to intercept the touch.

To check the top or bottom try:

 int scrollRange = computeVerticalScrollRange(); int scrollOffset = computeVerticalScrollOffset(); int scrollExtend = computeVerticalScrollExtent(); if(scrollOffset == 0){ //AtTop }else if(scrollRange == scrollOffset + scrollExtend){ //AtBottom } 
+2
source

Source: https://habr.com/ru/post/1492045/


All Articles