我尝试禁用特定角度的垂直 ScrollView,但未成功。
这背后的目标是正确处理嵌套在垂直 ScrollView 中的多个水平 ListView。
我试过这个,但它不工作:
public class VScrollView extends ScrollView {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public VScrollView(Context context) {
super(context);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
public VScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
public VScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (e1 != null && e2 != null) {
double delta_x = (e1.getX() - e2.getX());
double delta_y = (e1.getY() - e2.getY());
double radians = Math.abs(Math.toDegrees(Math.atan2(delta_y, delta_x)));
if (radians > 80 && radians < 100) {
return true;
}
}
return false;
}
}
}