SlidingMenu 的侧变栏是无法滑动的,只能够拖动主页面进行滑动, 感觉特别不方便,对应有强迫症的人来说实在是不好受.
要实现侧边栏的滑动,只能改源码.
1.找到CustomViewAbove.java 文件 将
prive boolean mIsBeingDragged;
改为:
public static boolean mIsBeingDragged;
2.在CustomViewBehind.java 文件 中,找到 onInterceptTouchEvent 和 onTouchEvent 的位置.改成如下:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
//1. 记录坐标
mDownX= ev.getX();
mDownY= ev.getY();
break;
case MotionEvent.ACTION_MOVE:
//2.记录结束值
float endX= ev.getX();
float endY= ev.getY();
//3. 计算绝对值
float distanceX= Math.abs(endX-mDownX);
float distanceY= Math.abs(endY- mDownY);
if (distanceX>distanceY && distanceX>5) {
System.out.println("移动");
//想办法让slidingMenu滑动
CustomViewAbove.mIsBeingDragged =true;
mViewAbove.onTouchEvent(ev);
return true;
}else {
System.out.println("点击");
return !mChildrenEnabled;
}
// break;
case MotionEvent.ACTION_UP:
CustomViewAbove.mIsBeingDragged =true;
mViewAbove.onTouchEvent(ev);
break;
}
return !mChildrenEnabled;
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()){
case MotionEvent.ACTION_DOWN:
//1. 记录坐标
mDownX= ev.getX();
mDownY= ev.getY();
break;
case MotionEvent.ACTION_MOVE:
//2.记录结束值
float endX= ev.getX();
float endY= ev.getY();
//3. 计算绝对值
float distanceX= Math.abs(endX-mDownX);
float distanceY= Math.abs(endY- mDownY);
if (distanceX>distanceY && distanceX>5) {
//想办法让slidingMenu滑动
CustomViewAbove.mIsBeingDragged =true;
mViewAbove.onTouchEvent(ev);
}else {
return !mChildrenEnabled;
}
break;
case MotionEvent.ACTION_UP:
CustomViewAbove.mIsBeingDragged =true;
mViewAbove.onTouchEvent(ev);
break;
}
return true;
}
注意: 把 mDownX, mDownY 设置为全局变量. 即可实现侧边栏的滑动.