Skip to content

Instantly share code, notes, and snippets.

@XjojoX1989
Created April 5, 2020 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XjojoX1989/516dfade2980ec8a6aaf3bc86d940ae6 to your computer and use it in GitHub Desktop.
Save XjojoX1989/516dfade2980ec8a6aaf3bc86d940ae6 to your computer and use it in GitHub Desktop.
public boolean dispatchTouchEvent(MotionEvent event) {
int x = (int) event.getX();
int y = (int) event.getY();
switch (event.getAction) {
case MotionEvent.ACTION_DOWN:
parent.requestDisallowInterceptTouchEvent(true);//true表示禁止父容器攔截
break;
case MotionEvent.ACTION_MOVE:
int deltaX = x - mLastX;
int deltaY = y - mLastY;
if (父容器需要此类点击事件) {
parent.requestDisallowInterceptTouchEvent(false);
}
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
mLastX = x;
mLastY = y;
return super.dispatchTouchEvent(event);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment