Set OnTouchListener for inner view. In onTouch()
method, call:
viewPager.requestDisallowInterceptTouchEvent(true)
ViewPager handles its swiping motion in onInterceptTouchEvent()
. Above code prevents ViewPager from calling onInterceptTouchEvent()
. When you're swiping, ViewPager returns true in onInterceptTouchEvent()
which also prevents touch events to be passed to child views. Therefore disallowing intercept allows child views to handle touch events.
Set back to false
when the inner view is not being touched.
From my experience, onInterceptTouchEvent()
prevents onTouchEvent()
. It does not prevent OnTouchListener
. So the key here is to set up OnTouchListener
for the inner view.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…