I have a couple of custom views in a viewpager
and I find the viewpager's
ontouch
event will conflict with the ontouchevent
of the custom view which will result in that I can not drag the custom view around as expected. To resolve this problem I try to set the ontouchevent
of the custom view to return true but the touchevent
of viewpager
still gets triggered. How Can I prevent the viewpager
from being processing ontouchevent
? Any help is much appreciated!
The ViewPager uses onInterceptTouchEvent()
to get the touches before its children. Take a look at the docs and overwrite onInterceptTouchEvent()
of the Pager as you like.
The onInterceptTouchEvent() method is called whenever a touch event is detected on the surface of a ViewGroup, including on the surface of its children. If onInterceptTouchEvent() returns true, the MotionEvent is intercepted, meaning it will be not be passed on to the child, but rather to the onTouchEvent() method of the parent.