最近的项目中实现订单肯定页面。须要使用ScrollView嵌套RecyclerView,当RecyclerView中的item数量比较多时,就会出现item只显示一部分数据,并无将用户勾选的商品数量所有显示出来,这个时候就须要咱们作一下处理了。android
下面来讲两种解决方案:bash
一、使用5.0的新控件NestedScrollView替换ScrollView. NestedScrollView支持嵌套滑动,既能填item显示不全的坑,又能够填嵌套滑动卡顿的坑。不了解的童鞋能够去学习一波,这里就不作详细的说明了。布局
用法: (1)、布局文件中将ScrollView替换成"android.support.v4.widget.NestedScrollView". (2)、使用代码设置recyclerView.setNestedScrollingEnabled(false)便可。学习
二、在RecyclerView的外面嵌套一层RelativeLayout,而后添加属性 android:descendantFocusability="blocksDescendants".spa
用法参考:code
<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>
复制代码
说到这咱们再来熟悉一下 android:descendantFocusability="blocksDescendants"属性的做用:cdn
该属性的含义是:当一个view获取焦点时,定义ViewGroup和其子控件二者之间的关系。图片
它一共有3个属性值,它们分别是:get
beforeDescendants:viewGroup会优先子类控件而获取焦点;同步
afterDescendants:viewGroup只有当子类控件不须要获取焦点的时候才去获取焦点;
blocksDescendants:viewGroup会覆盖子类控件而直接获取焦点。
两种方案到这里就介绍完了。
如下是我的公众号(longxuanzhigu),以后发布的文章会同步到该公众号,方便交流学习Android知识及分享我的爱好的文章,有问题能够留言哦: