解决ScrollView嵌套RecyclerView时item显示不全的问题

来源:互联网 发布:北通 知乎 编辑:程序博客网 时间:2024/06/05 20:22

问题:ScrollView嵌套RecyclerView时,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_list"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="20dp">    </android.support.v7.widget.RecyclerView></RelativeLayout>
不过此种方法在上下滑动时如果手指滑动区域在RecyclerView区域内会有粘稠感滑动不流畅。

第二种方法:在xml布局文件中将ScrollView替换成android.support.v4.widget.NestedScrollView,并在java代码中设置recyclerView.setNestedScrollingEnabled(false);属性。



阅读全文
0 0