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);
        }

    这样就完美解决了

  • 相关阅读:
    [Android学习笔记]some tips
    ubuntu desktop 开机 连接网络
    ubuntn svn 安装 配置
    ubuntu 安装phpmyadmin
    ubuntu 安装flash插件
    ubuntu samba共享安装 配置
    ubuntu tengine 安装
    ubuntu vim之php函数提示
    ubuntu vim 插件安装
    nyoj-709-异 形 卵
  • 原文地址:https://www.cnblogs.com/dubo-/p/7086515.html
Copyright © 2011-2022 走看看