I've a layout in which Custom ScrollView has Horizontal viewpager and TextView below it. The onClick of TextView stops working if I use InterpretedScrollView instead of ScrollView. I need InterpretedScrollView to allow horizontal scroll in ViewPager.
<com.package.InterceptedScrollView
<ViewPager
// scrolls horizontally thanks to InterceptedScrollView
/>
...
<TextView
// try scrolling vertically by touching this imageView and it doesn't scroll
onClick="something"/>
</com.package.InterceptedScrollView>
and my custom ScrollView
public class InterceptedScrollView extends ScrollView {
GestureDetector mGestureDetector;
private class VerticalScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float x, float y) {
if (Math.abs(y) > Math.abs(x)) {
// scrolling in Y direction essentially. Should scroll
// vertically.
return true;
}
// Not much of scroll in Y. Don't scroll.
return false;
}
}
public InterceptedScrollView(Context ctx, AttributeSet as) {
super(ctx, as);
mGestureDetector = new GestureDetector(ctx, new VerticalScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return super.onInterceptTouchEvent(event) && mGestureDetector.onTouchEvent(event);
}
}
Why is My InterceptedScrollview eating onClick of the TextView? How do I fix it?