Android 6.0以上系统的 RecyclerView 在HorizontalScrollView或者Scrollview中显示不全问题

来源:互联网 发布:极品网络女神sally 编辑:程序博客网 时间:2024/05/16 16:06

做项目一直用5.0的手机没出现这个问题后来 换成了7.0的,出现了显示问题 只能显示当前页面的数据,后面的数据滑动不出来,

一开始以为是滑动问题。后才经验证是显示不全的问题上网找到了解决方法 记录下来希望对大家有所帮助



就是在Recyclerview外层加一个RelativeLayout    

关键代码是

    android:descendantFocusability="blocksDescendants"


意思是android:descendantFocusability="blocksDescendants"

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

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

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

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



贴上整体嵌套的代码  谢谢大家


<com.kenfeng.kfhjlr.kfzy.Activity.CustomView.NoScrollHorizontalScrollView

    android:id="@+id/sv_title"    android:layout_width="wrap_content"    android:layout_height="30dp"    android:layout_toRightOf="@id/tv_name"    android:scrollbars="none">    <RelativeLayout        android:layout_width="wrap_content"        android:layout_height="30dp"        android:descendantFocusability="blocksDescendants">        <android.support.v7.widget.RecyclerView            android:id="@+id/rv_top"            android:layout_width="match_parent"            android:layout_height="match_parent" />    </RelativeLayout></com.kenfeng.kfhjlr.kfzy.Activity.CustomView.NoScrollHorizontalScrollView>

阅读全文
0 0
原创粉丝点击