zoukankan      html  css  js  c++  java
  • Android6.0以上关于RecyclerView显是不全的问题

    Android6.0以上关于RecyclerView显是不全的问题

    需求描述

    适配的时候发现Android 6.0以上,RecyclerView显示不全,以下是没有问题的。
    这个时候查看布局文件,可以看到RecyclerView是嵌套在ScrollView中的。

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="never"
                android:paddingLeft="16dp"
                android:paddingRight="16dp" />
        </ScrollView>
    

    解决方法

    第一种解决方法

    方法

    在RecyclerView上在嵌套上一层RelativeLayout,添加属性android:descendantFocusability=”blocksDescendants”(当一个view获取焦点时,viewGroup会覆盖子类控件而直接获取焦点)解决嵌套卡顿的问题。

    注意,设立只能使用RelativeLayout,使用FrameLayout、LinearLayout等其他常用的布局控件是不行的。亲测。

    代码
     <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:descendantFocusability="blocksDescendants">
    
                <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:overScrollMode="never"
                    android:paddingLeft="16dp"
                    android:paddingRight="16dp" />
    
            </RelativeLayout>
        </ScrollView>
    

    第二种解决方法

    方法

    使用android.support.v4.widget.NestedScrollView替代ScrollView,并在代码中设置recyclerView.setNestedScrollingEnabled(false)(设置是否允许嵌套滑动)。既可以填ITEM显示不全的坑,又可以填嵌套滑动卡顿的坑。

    代码
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="never"
                android:paddingLeft="16dp"
                android:paddingRight="16dp" />
        </android.support.v4.widget.NestedScrollView>
    
    recyclerView.setNestedScrollingEnabled(false);
    

    总结

    相比较而言,个人觉得第二种解决方法更好,第一种方法布局嵌套,总有一种想让人优化的冲动,所以觉得第二种解决方法更好。

  • 相关阅读:
    EZchip花1.3亿美元买Tilera然后以8亿美元把自己与Tilera一起卖掉
    [OFC]Mellanox发布首个200Gb/s硅光子设备
    Mellanox 8亿美元收购EZchip
    EZchip将推全球首款100核64位ARM A-53芯片
    MyBatis映射文件5
    MyBatis映射文件4(参数获取#{}和${}/select标签详解[返回类型为list])
    MyBatis源码分析1 参数映射分析
    MyBatis映射文件3(参数处理Map)
    MyBatis映射文件2(不支持自增的数据库解决方案/参数处理[单参、多参、命名参数])
    MyBatis映射文件1(增删改、insert获取自增主键值)
  • 原文地址:https://www.cnblogs.com/zhangmiao14/p/9538979.html
Copyright © 2011-2022 走看看