简体   繁体   中英

How to prevent a custom view passing touch events to parent viewpager

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM