Skip to content

Commit

Permalink
Optimize the slidinng process,repair 滑动不灵敏 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklygaj committed Jul 10, 2017
1 parent 8cc0043 commit 2d8ce58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;

}
Expand Down

0 comments on commit 2d8ce58

Please sign in to comment.