0
我試過沒有成功禁用垂直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;
}
}
}