核心就是判断滑动事件 纵向 父控件控制 横向 自己控制 不给父控件控制权限
上代码
public class CustomRecyclerView extends RecyclerView {
private int mTouchSlop;
public CustomRecyclerView(Context context) {
super(context);
final ViewConfiguration vc = ViewConfiguration.get(context);
mTouchSlop = vc.getScaledTouchSlop();
}
public CustomRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
final ViewConfiguration vc = ViewConfiguration.get(context);
mTouchSlop = vc.getScaledTouchSlop();
}
int move_x,move_y;
@Override
public boolean onTouchEvent(MotionEvent e) {
switch (e.getAction()){
case MotionEvent.ACTION_DOWN:
move_x = (int) e.getX();
move_y = (int) e.getY();
getParent().requestDisallowInterceptTouchEvent(true);
Log.e("motion_event","down x==y "+move_x+" ==== "+move_y);
break;
case MotionEvent.ACTION_MOVE:
Log.e("motion_event","move x==y "+move_x+" ==== "+move_y);
int y = (int) e.getY();
int x = (int) e.getX();
if(Math.abs(y-move_y)>mTouchSlop&&Math.abs(x-move_x)<mTouchSlop*2){
getParent().requestDisallowInterceptTouchEvent(false);
}else {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_UP:
Log.e("motion_event","up x==y "+move_x+" ==== "+move_y);
getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return super.onTouchEvent(e);
}
}
问题解决
哈哈哈哈(周星驰笑)