解决ScrollView滑动RecyclerView的卡顿

我们不的不了解ViewConfiguration这个类,官方是这么解释的Contains methods to standard constants used in the UI for timeouts, sizes, and distances 

                           //包含方法用于超时,UI标准常数大小和距离

/**

 * @return Distance in pixels a touch can wander before we think the user is scrolling    其实就是用户滚动的像素点的距离
*/
public int getScaledTouchSlop() {
return mTouchSlop;
}

有了这个方法是不是就有点头绪了呢

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;
                }
        }
        Log.i(Tag,"onInterceptTouchEvent");
        return super.onInterceptTouchEvent(e);
    }

这样就完美解决了

原文地址:https://www.cnblogs.com/dubo-/p/7086515.html