1.嵌套的滑動問題
一般來說,當ScrollView嵌套RecyclerView的時候,我們會發(fā)現(xiàn)這兩個控件的滑動會出現(xiàn)問題,滑到RecyclerView的頂部才有所卡頓。所以我們采用NestedScrollView代替ScrollView,把滑動的動作交給了NestedScrollView,這個問題就可以解決了.....
xml:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.core.widget.NestedScrollView>
如果覺得滑動Recyclerview不夠流暢可以在控件里添加一下屬性:
//設置嵌套滑動是否能用
android:nestedScrollingEnabled="false"
2.嵌套的顯示問題
當跳轉到該頁面時,頁面不會從頁面頂部開始顯示,會從RecyclerView第一個Item的位置開始顯示,原因是Recyclerview獲取了焦點導致的。解決方法如下:
1.把ScrollView更換為NestedScrollView
2.在不更換的前提下,可以讓頂部的某一個控件獲取焦點即可
android:focusable="true"
本人也第一次寫博客,不足的地方還要多多改善,如果本文章對您有幫助,麻煩給個點贊。