说明:如果返回值是true :表示拦截成功,反之拦截失败
private int lastY;
private int lastX, downX, downY;
//父视图对子试图的拦截操作
//如果返回值是true :表示拦截成功,反之拦截失败
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean isIntercept = false;
int eventY = (int) ev.getY();
int eventX = (int) ev.getX();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
lastX = downX = eventX;
lastY = downY = eventY;
break;
case MotionEvent.ACTION_MOVE:
int totalX = Math.abs(eventX - downX);
int totalY = Math.abs(eventY - downY);
if (totalY > totalX && totalY > 10) {
isIntercept = true;
}
lastX = eventX;
lastY = eventY;
break;
case MotionEvent.ACTION_UP:
break;
}
return isIntercept;
}
希望能对大家有所帮助,欢迎大家一起讨论交流.
3952735fe4a07d74f844ab84d36c43b0_r.jpg
网友评论