1、建一个类,继承scrollview,重写里面的方法:
/** * 屏蔽 滑动事件 * * Created by 潘洲涛 on 2017/1/1. */ class MyScrollview extends ScrollView { private int downX; private int downY; private int mTouchSlop; public MyScrollview(Context context) { super(context); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } public MyScrollview(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent(MotionEvent e) { int action = e.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: downX = (int) e.getRawX(); downY = (int) e.getRawY(); break; case MotionEvent.ACTION_MOVE: int moveY = (int) e.getRawY(); if (Math.abs(moveY - downY) > mTouchSlop) { return true; } } return super.onInterceptTouchEvent(e); } }
2、在xml文件中引用:
<com.pan.skating.view.MyScrollview android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/act_recycle_super_video_recycleview" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.pan.skating.view.MyScrollview>
这样就可以了。