From f9650a44ff91dbeeb02eeaeed6154cf4d58ebe03 Mon Sep 17 00:00:00 2001 From: yangyufei Date: Fri, 18 Jan 2019 20:16:21 +0800 Subject: [PATCH] =?UTF-8?q?fix-=E7=A9=BA=E7=99=BD=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=E5=87=BA=E5=8F=91=E6=BB=91=E5=8A=A8=EF=BC=8C=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .settings/org.eclipse.buildship.core.prefs | 2 -- .../library/NestedTouchScrollingLayout.java | 25 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) delete mode 100644 .settings/org.eclipse.buildship.core.prefs diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs deleted file mode 100644 index e889521..0000000 --- a/.settings/org.eclipse.buildship.core.prefs +++ /dev/null @@ -1,2 +0,0 @@ -connection.project.dir= -eclipse.preferences.version=1 diff --git a/library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java b/library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java index 70ac587..1171f6b 100644 --- a/library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java +++ b/library/src/main/java/jarvis/com/library/NestedTouchScrollingLayout.java @@ -267,10 +267,33 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { } } + private boolean isTouchUnderChildView(MotionEvent event) { + View targetChildView = getChildAt(0); + float translationX = targetChildView.getTranslationX(); + float translationY = targetChildView.getTranslationY(); + float x = event.getX(); + float y = event.getY(); + return x >= targetChildView.getLeft() + translationX && + x <= targetChildView.getRight() + translationX && + y >= targetChildView.getTop() + translationY && + y <= targetChildView.getBottom() + translationY; + } + + /** + * 不拦截 Touch 事件的几种情况 + * 1.不开启父亲布局拦截. + * 2.当前子 View 为 null + * 3.当前 Touch 事件没用作用到子 View + * @param event + * @return + */ @Override public boolean onTouchEvent(MotionEvent event) { float velocityY = 0; - if (getChildAt(0) == null || !isParentDispatchTouchEvent) { + + if (!isParentDispatchTouchEvent || + getChildAt(0) == null || + !isTouchUnderChildView(event)) { return super.onTouchEvent(event); } if (isAnimating()) {