我有一个布局,其中 Custom ScrollView 在其下方有 Horizontal viewpager 和 TextView。如果我使用 InterpretedScrollView 而不是 ScrollView,则 TextView 的 onClick 将停止工作。我需要 InterpretedScrollView 以允许在 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>
和我的自定义 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);
}
}
为什么我的 InterceptedScrollview 会吃掉 TextView 的 onClick?我如何解决它?