ScrollView嵌套RecyclerView出现item显示不全的问题

ScrollView嵌套RecyclerView出现item显示不全的问题

第一种:在你的RecyclerView上外边嵌套一层RelativeLayout,

然后添加属性 android:descendantFocusability="blocksDescendants"

如:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_meeting"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>

PS:既然提到了这个属性就说下它的意思吧,知道的同学再复习一遍呗,巩固巩固更牢靠。

属性android:descendantFocusability的含义是:当一个view获取焦点时,定义ViewGroup和其子控件两者之间的关系。

它一共有3个属性值,它们分别是:

beforeDescendants:viewGroup会优先子类控件而获取焦点

afterDescendants:viewGroup只有当子类控件不需要获取焦点的时候才去获取焦点

blocksDescendants:viewGroup会覆盖子类控件而直接获取焦点

第二种方法:

首先在xml布局中将你的ScrollView替换成android.support.v4.widget.NestedScrollView,

并在java代码中设置recyclerView.setNestedScrollingEnabled(false);

PS:第二中方法是啊网上查到的,自己没有试NestedScrollView这个东西是5.0的新控件,有机会试试,先记录下来。

猜你喜欢

转载自blog.csdn.net/hanxiongwei/article/details/81635281
今日推荐