This is usually done through the parent method onInterceptTouchEvent . onInterceptTouchEvent has the ability to see some kind of touch event before children make the view. If onInterceptTouchEvent returns true child view that previously handled touch events receives ACTION_CANCEL , and events from this point forward are sent to the parent onTouchEvent method for normal processing. It can also return false and simply track events when they move down the view hierarchy to their usual goals.
You want to do this essentially in onInterceptTouchEvent in the parent view, where you detect pop-ups:
- In
ACTION_DOWN record the location of the touch. Return false . - In
ACTION_MOVE , check the delta between the initial touch down and the current position. If it passes the threshold (the structure uses ViewConfiguration#getScaledTouchSlop() or other appropriate values ββfrom ViewConfiguration for things like this,) return true . onTouchEvent detection and control, as usual, is based on onTouchEvent .
Once you intercept, ListView will cancel touch processing and you will not receive unwanted tap events in your lists. ListView also configured to prevent its parent process from catching events as soon as the user starts scrolling vertically in the list, which means that you wonβt be mistaken for horizontal throws if the user sloppily displays the list vertically.
This is how things like Android Launcher or News and Weather do side-swipe scroll / swap content.
adamp source share