解决办法之一重写SlidingPaneLayout的onInterceptTouchEvent事件
原理:监听手指的动作
public class one extends SlidingPaneLayout{
private float minitialmotionx;//落下x
private float minitialmotiony;//落下y
private float medgeslop;//得到手机屏幕的数据
public one(Context context) {
this(context, null);
}
public one(Context context, AttributeSet attrs) {
this(context,attrs,0);
}
public one(Context context,AttributeSet attrs, int defstyle) {
super(context, attrs, defstyle);
ViewConfiguration config = ViewConfiguration.get(context);
medgeslop = config.getScaledEdgeSlop();//得到手机屏幕的数据
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_DOWN: {//手指落下
minitialmotionx = ev.getX();
minitialmotiony = ev.getY();
break;
}
case MotionEvent.ACTION_MOVE: {//手指离开,计算距离
final float x = ev.getX();
final float y = ev.getY();
if (minitialmotionx > medgeslop && !isOpen() && canScroll(this, false,
Math.round(x - minitialmotionx), Math.round(x), Math.round(y))) {//isOpen()侧滑是否打开
//canScroll(this, false,Math.round(x - minitialmotionx), Math.round(x), //Math.round(y))是否滑动
MotionEvent cancelevent = MotionEvent.obtain(ev);//得到事件
cancelevent.setAction(MotionEvent.ACTION_CANCEL);//设置事件
return super.onInterceptTouchEvent(cancelevent);//返回事件
}
}
}
return super.onInterceptTouchEvent(ev);//回调,不能返回true或者false
}
}