ScrollView里嵌套 RecyclerVIew 时,拦截RecyclerVIew 触摸事件

    xiaoxiao2021-03-25  102

    ScrollView里嵌套 RecyclerVIew 时,拦截RecyclerVIew 触摸事件:

    public class InterceptScrollView extends ScrollView { private int mDownY; private int mTouchSlop; public InterceptScrollView(Context context) { this(context,null); } public InterceptScrollView(Context context, AttributeSet attrs) { super(context, attrs); //触发移动事件的最短距离,如果小于这个距离就不触发移动控件 mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()){ case MotionEvent.ACTION_DOWN: mDownY = (int) ev.getRawY(); break; case MotionEvent.ACTION_MOVE: int moveY = (int) ev.getRawY(); if (Math.abs(mDownY - moveY) > mTouchSlop){ //拦截事件,自己消费 return true; } break; } return super.onInterceptTouchEvent(ev); } }
    转载请注明原文地址: https://ju.6miu.com/read-16369.html

    最新回复(0)