Created
April 5, 2020 09:14
-
-
Save XjojoX1989/ecb167b94130bb0264705e0b1674a75c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//重寫父容器的攔截方法 | |
public boolean onInterceptTouchEvent(MotionEvent event) { | |
boolean intercepted = false; | |
int x = (int) event.getX(); | |
int y = (int) event.getY(); | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_DOWN://ACTION_DOWN事件必須返回false,一但攔截後續事件將不能傳遞給子View | |
intercepted = false; | |
break; | |
case MotionEvent.ACTION_MOVE://ACTION_MOVE事件根據需要決定是否攔截 | |
if (父容器需要当前事件){ | |
intercepted = true; | |
} else{ | |
intercepted = flase; | |
} | |
break; | |
case MotionEvent.ACTION_UP://对于ACTION_UP事件必须返回false,一旦拦截子View的onClick事件将不会触发 | |
intercepted = false; | |
break; | |
default: | |
break; | |
} | |
mLastXIntercept = x; | |
mLastYIntercept = y; | |
return intercepted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment