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

 

正常情況下,由於NestedScrollView/ScrollView 嵌套RecyclerView,可能會導致Recyclerview佔據焦點導致整個NestedScrollView/ScrollView內容上滑。

此問題解決方案如下:

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

android:descendantFocusability 有三種值:

beforeDescendants:viewgroup會優先其子類控件而獲取到焦點

afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點

blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點

這種方法,會造成頁面中Editext焦點被搶導致無法輸入,需要用到第二種方法。

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

android:focusable="true"

android:focusableInTouchMode="true"

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

android:focusable="true"

android:focusableInTouchMode="true"

4.在listview 外面佈局使用

android:focusable="true"

android:focusableInTouchMode="true"

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章