最近的項目中實現訂單肯定頁面。須要使用ScrollView嵌套RecyclerView,當RecyclerView中的item數量比較多時,就會出現item只顯示一部分數據,並無將用戶勾選的商品數量所有顯示出來,這個時候就須要咱們作一下處理了。android
下面來講兩種解決方案:佈局
一、使用5.0的新控件NestedScrollView替換ScrollView.
NestedScrollView支持嵌套滑動,既能填item顯示不全的坑,又能夠填嵌套滑動卡頓的坑。不瞭解的童鞋能夠去學習一波,這裏就不作詳細的說明了。學習
用法:
(1)、佈局文件中將ScrollView替換成"android.support.v4.widget.NestedScrollView".
(2)、使用代碼設置recyclerView.setNestedScrollingEnabled(false)便可。spa
二、在RecyclerView的外面嵌套一層RelativeLayout,而後添加屬性 android:descendantFocusability="blocksDescendants".code
用法參考:blog
<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"屬性的做用:圖片
該屬性的含義是:當一個view獲取焦點時,定義ViewGroup和其子控件二者之間的關係。get
它一共有3個屬性值,它們分別是:同步
beforeDescendants:viewGroup會優先子類控件而獲取焦點;it
afterDescendants:viewGroup只有當子類控件不須要獲取焦點的時候纔去獲取焦點;
blocksDescendants:viewGroup會覆蓋子類控件而直接獲取焦點。
兩種方案到這裏就介紹完了。
如下是我的公衆號(longxuanzhigu),以後發佈的文章會同步到該公衆號,方便交流學習Android知識及分享我的愛好的文章,有問題能夠留言哦: