Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chkDragable(), 有问题 #45

Open
yzykami opened this issue Oct 11, 2017 · 1 comment
Open

chkDragable(), 有问题 #45

yzykami opened this issue Oct 11, 2017 · 1 comment

Comments

@yzykami
Copy link

yzykami commented Oct 11, 2017

private void chkDragable() {
setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View view, MotionEvent motionEvent) {

             if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                 lastY = motionEvent.getRawY();
                 lastX = motionEvent.getRawX();
             } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                 newY = motionEvent.getRawY();

---------------------"lastX = motionEvent.getRawX();"------------------------

                 offsetY = Math.abs(newY - lastY);
                 lastY = newY;

                 offsetX = Math.abs(newX - lastX);
                 lastX = newX;

                 switch (dragEdge) {
                     case TOP:
                     case BOTTOM:
                         setEnablePullToBack(offsetY > offsetX);
                     case LEFT:
                     case RIGHT:
                         setEnablePullToBack(offsetY < offsetX);
                         break;
                 }
             }

             return false;
         }
     });
  }		      

}

标注的地方, 应该是
newX = motionEvent.getRawX();
但是修改之后, 拖拽就失效了

@WarpGateX
Copy link

我这对做了些处理,拖拽失效我看了下,应该是ViewDragHelper 中 tryCaptureViewForDrag()方法里获取mCallback.tryCaptureView()的回调判断在 Touch方法之前先执行而在newX = motionEvent.getRawX();之后若有false返回一次,那下一次一直就以false返回,onInterceptTouchEvent() 就一直返回false,导致拖拽失效。

我这边的处理
@OverRide
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean handled = false;
ensureTarget();
checkPullBack(ev);//在这里加上touch方法里的偏移判断
if (isEnabled()) {
handled = viewDragHelper.shouldInterceptTouchEvent(ev);
} else {
viewDragHelper.cancel();
}
return !handled ? super.onInterceptTouchEvent(ev) : handled;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants