Android解决RecyclerView中的item显示不全方案

最近的项目中实现订单确定页面。需要使用ScrollView嵌套RecyclerView,当RecyclerView中的item数量比较多时,就会出现item只显示一部分数据,并没有将用户勾选的商品数量全部显示出来,这个时候就需要我们做一下处理了。

下面来说两种解决方案:

1、使用5.0的新控件NestedScrollView替换ScrollView.
NestedScrollView支持嵌套滑动,既能填item显示不全的坑,又可以填嵌套滑动卡顿的坑。不了解的童鞋可以去学习一波,这里就不做详细的说明了。

用法:
(1)、布局文件中将ScrollView替换成"android.support.v4.widget.NestedScrollView".
(2)、使用代码设置recyclerView.setNestedScrollingEnabled(false)即可。

2、在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/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never"/> </RelativeLayout>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdygz.html