zoukankan      html  css  js  c++  java
  • 解决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);
        }

    这样就完美解决了

  • 相关阅读:
    移动布局---1. 移动端布局基础
    1. CSS新特性之选择器
    1. H5新增语义化标签
    POJ 3281
    poj 1986
    POJ 3728
    poj 2763
    poj 2749
    uva 11294
    LA 3713
  • 原文地址:https://www.cnblogs.com/dubo-/p/7086515.html
Copyright © 2011-2022 走看看