NestedScrollView、ScrollView 加載完自動滑動至底部問題的解決方案

正常狀況下,因爲NestedScrollView/ScrollView 嵌套RecyclerView,可能會致使Recyclerview佔據焦點致使整個NestedScrollView/ScrollView內容上滑。android

此問題的解決方案以下:佈局

1. 在根佈局設置android:descendantFocusability=」blocksDescendants」 ;spa

android:descendantFocusability 有三種值:
beforeDescendants:viewgroup會優先其子類控件而獲取到焦點
afterDescendants:viewgroup只有當其子類控件不須要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控件而直接得到焦點
這種方法,會形成頁面中Editext焦點被搶致使沒法輸入,須要用到第二種方法。

2, 對於有Editext的頁面須要在根佈局使用 :code

android:focusable="true"
android:focusableInTouchMode="true"

3. 在NestedScrollView/ScrollView頂部第一個控件使用 :blog

android:focusable="true"
android:focusableInTouchMode="true"
相關文章
相關標籤/搜索