diff --git a/README.md b/README.md index e8af6d7..3d31e13 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ A sliding menu library not just for recyclerview, but all views. - You need to add library dependencies infomation to build.gradle in your module. - compile 'com.github.anzaizai:EasySwipeMenuLayout:1.0.6' + compile 'com.github.anzaizai:EasySwipeMenuLayout:1.0.7' -- last releases version is 1.0.6 can be use +- last releases version is 1.0.7 can be use ## step 3 - User EasySwipeMenuLayout as the top-level root layout the needs to be added slide swipe menu the funcation views. diff --git a/app/build.gradle b/app/build.gradle index 5ec0ffe..64b2e9e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,9 +27,9 @@ dependencies { compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9' testCompile 'junit:junit:4.12' - compile 'com.github.anzaizai:EasySwipeMenuLayout:1.0.6' + // compile 'com.github.anzaizai:EasySwipeMenuLayout:1.0.6' -// compile project(':easyswipemenulibrary') + compile project(':easyswipemenulibrary') compile 'com.android.support:recyclerview-v7:25.+' compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18' diff --git a/easyswipemenulibrary/src/main/java/com/guanaj/easyswipemenulibrary/EasySwipeMenuLayout.java b/easyswipemenulibrary/src/main/java/com/guanaj/easyswipemenulibrary/EasySwipeMenuLayout.java index e41c4f2..4061730 100644 --- a/easyswipemenulibrary/src/main/java/com/guanaj/easyswipemenulibrary/EasySwipeMenuLayout.java +++ b/easyswipemenulibrary/src/main/java/com/guanaj/easyswipemenulibrary/EasySwipeMenuLayout.java @@ -41,6 +41,7 @@ public class EasySwipeMenuLayout extends ViewGroup { private Scroller mScroller; private static EasySwipeMenuLayout mViewCache; private static State mStateCache; + private float distanceX; public EasySwipeMenuLayout(Context context) { this(context, null); @@ -254,8 +255,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) { if (mViewCache != this) { mViewCache.handlerSwipeMenu(State.CLOSE); } - // Log.i(TAG, ">>>有菜单被打开"); - + // Log.i(TAG, ">>>有菜单被打开"); getParent().requestDisallowInterceptTouchEvent(true); } @@ -264,38 +264,38 @@ public boolean dispatchTouchEvent(MotionEvent ev) { case MotionEvent.ACTION_MOVE: { // System.out.println(">>>>dispatchTouchEvent() ACTION_MOVE getScrollX:" + getScrollX()); - float distanceX = mLastP.x - ev.getRawX(); + distanceX = mLastP.x - ev.getRawX(); float distanceY = mLastP.y - ev.getRawY(); if (Math.abs(distanceY) > mScaledTouchSlop * 2) { break; } - //当处于水平滑动时,禁止父类拦截 - if (Math.abs(distanceX) > mScaledTouchSlop * 2 || Math.abs(getScrollX()) > mScaledTouchSlop * 2) { - // Log.i(TAG, ">>>>当处于水平滑动时,禁止父类拦截 true"); - getParent().requestDisallowInterceptTouchEvent(true); - - scrollBy((int) (distanceX), 0);//滑动使用scrollBy - - //越界修正 - if (getScrollX() < 0) { - if (!mCanRightSwipe || mLeftView == null) { - scrollTo(0, 0); - } else {//左滑 - if (getScrollX() < mLeftView.getLeft()) { - scrollTo(mLeftView.getLeft(), 0); - } - + // Log.i(TAG, ">>>>>distanceX:" + distanceX); + + scrollBy((int) (distanceX), 0);//滑动使用scrollBy + //越界修正 + if (getScrollX() < 0) { + if (!mCanRightSwipe || mLeftView == null) { + scrollTo(0, 0); + } else {//左滑 + if (getScrollX() < mLeftView.getLeft()) { + scrollTo(mLeftView.getLeft(), 0); } - } else if (getScrollX() > 0) { - if (!mCanLeftSwipe || mRightView == null) { - scrollTo(0, 0); - } else { - if (getScrollX() > mRightView.getRight() - mContentView.getRight() - mContentViewLp.rightMargin) { - scrollTo(mRightView.getRight() - mContentView.getRight() - mContentViewLp.rightMargin, 0); - } + + } + } else if (getScrollX() > 0) { + if (!mCanLeftSwipe || mRightView == null) { + scrollTo(0, 0); + } else { + if (getScrollX() > mRightView.getRight() - mContentView.getRight() - mContentViewLp.rightMargin) { + scrollTo(mRightView.getRight() - mContentView.getRight() - mContentViewLp.rightMargin, 0); } } } + //当处于水平滑动时,禁止父类拦截 + if (Math.abs(distanceX) > mScaledTouchSlop || Math.abs(getScrollX()) > mScaledTouchSlop) { + // Log.i(TAG, ">>>>当处于水平滑动时,禁止父类拦截 true"); + getParent().requestDisallowInterceptTouchEvent(true); + } mLastP.set(ev.getRawX(), ev.getRawY()); break; @@ -335,12 +335,14 @@ public boolean onInterceptTouchEvent(MotionEvent event) { } case MotionEvent.ACTION_MOVE: { //滑动时拦截点击时间 - float distance = mLastP.x - event.getRawX(); - if (Math.abs(distance) > mScaledTouchSlop) { + if (Math.abs(distanceX) > mScaledTouchSlop) { // 当手指拖动值大于mScaledTouchSlop值时,认为应该进行滚动,拦截子控件的事件 //Log.i(TAG, ">>>>onInterceptTouchEvent true"); return true; } + if (Math.abs(distanceX) > mScaledTouchSlop || Math.abs(getScrollX()) > mScaledTouchSlop) { + return true; + } break; }