From ba3053d70b91a12f884735075618cc65d665db66 Mon Sep 17 00:00:00 2001 From: idtk <623680332@qq.com> Date: Tue, 12 Sep 2017 22:07:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=8B=89=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A8=AA=E5=90=91=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在上下拉判断时,增加横向滑动距离条件,仅当垂直滑动距离大于横向滑动距离的情况下触发上下拉,增加后可以解决NestedScrollView>(嵌套)LinearLayot>(嵌套)套轮播图布局时,横向滑动误触引发的上下拉 --- .../lib/SuperSwipeRefreshLayout.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SuperSwipeRefreshLayout-Demo-AS/lib/src/main/java/com/github/nuptboyzhb/lib/SuperSwipeRefreshLayout.java b/SuperSwipeRefreshLayout-Demo-AS/lib/src/main/java/com/github/nuptboyzhb/lib/SuperSwipeRefreshLayout.java index 7c82577..d4827b3 100755 --- a/SuperSwipeRefreshLayout-Demo-AS/lib/src/main/java/com/github/nuptboyzhb/lib/SuperSwipeRefreshLayout.java +++ b/SuperSwipeRefreshLayout-Demo-AS/lib/src/main/java/com/github/nuptboyzhb/lib/SuperSwipeRefreshLayout.java @@ -82,6 +82,7 @@ public class SuperSwipeRefreshLayout extends ViewGroup { private boolean mOriginalOffsetCalculated = false; private float mInitialMotionY; + private float mInitialMotionX; private boolean mIsBeingDragged; private int mActivePointerId = INVALID_POINTER; private boolean mScale; @@ -653,10 +654,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; final float initialMotionY = getMotionEventY(ev, mActivePointerId); + final float initialMotionX = getMotionEventX(ev, mActivePointerId); if (initialMotionY == -1) { return false; } mInitialMotionY = initialMotionY;// 记录按下的位置 + mInitialMotionX = initialMotionX;// 记录按下的位置 case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { @@ -666,18 +669,20 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { } final float y = getMotionEventY(ev, mActivePointerId); + final float x = getMotionEventX(ev, mActivePointerId); if (y == -1) { return false; } float yDiff = 0; + float xDiff = mInitialMotionX - x; if (isChildScrollToBottom()) { yDiff = mInitialMotionY - y;// 计算上拉距离 - if (yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够 + if (Math.abs(xDiff)< yDiff && yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够 mIsBeingDragged = true;// 正在上拉 } } else { yDiff = y - mInitialMotionY;// 计算下拉距离 - if (yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够 + if (Math.abs(xDiff)< yDiff && yDiff > mTouchSlop && !mIsBeingDragged) {// 判断是否下拉的距离足够 mIsBeingDragged = true;// 正在下拉 } } @@ -706,6 +711,15 @@ private float getMotionEventY(MotionEvent ev, int activePointerId) { return MotionEventCompat.getY(ev, index); } + private float getMotionEventX(MotionEvent ev, int activePointerId) { + final int index = MotionEventCompat.findPointerIndex(ev, + activePointerId); + if (index < 0) { + return -1; + } + return MotionEventCompat.getX(ev, index); + } + @Override public void requestDisallowInterceptTouchEvent(boolean b) { // Nope.