Search code examples
javaandroidtouch-event

returning true in onTouchEvent and dispatchTouchEvent not working correct


I'm implementing an ImageView that can handle touch events and using it inside a ViewPager. In my ImageViews onTouchEvent and dispatchTouchEvent for testing I'm always returning true but it's not working correct and ViewPager is still working when I'm sliding on my ImageView. What am i doing wrong?


Solution

  • You aren't looking at the full touch chain. ViewPager implements onInterceptTouchEvent, which gets a chance to take touch events away from a child view. Look into requestDisallowInterceptTouchEvent on the ViewPager, and read up on the full touch handling chain at https://developer.android.com/training/gestures/viewgroup.html