Android 6.0 解决recyclerview 在 scrollview 中不能全部显示,高度不正常的问题

来源:互联网 发布:软件开发指南 编辑:程序博客网 时间:2024/05/30 23:47

前言:scrollview嵌套recyclerview,通过重写onInterceptTouchEvent 方法可以解决滚动的bug,6.0以下显示正常,但是在6.0不能全部显示,滚动也有问题。查了半天才找到。

滑动问题:

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

6.0显示不全问题:

关键代码是android:descendantFocusability="blocksDescendants"
该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点

afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

 <RelativeLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:descendantFocusability="blocksDescendants">                <android.support.v7.widget.RecyclerView                    android:id="@+id/menuRv"                    android:layout_width="match_parent"                    android:layout_height="wrap_content"                    android:layout_marginLeft="@dimen/margin_16"                    android:layout_marginRight="@dimen/margin_16">                </android.support.v7.widget.RecyclerView>  </RelativeLayout>

附上原文链接:http://www.jianshu.com/p/3815d36fd371?nomobile=yes

0 1
原创粉丝点击