NestedScrollView嵌套RecyclerView時自動滾動一段距離,頂部顯示不全

當在Fragment使用NestedScrollView嵌套RecyclerView時,來回切換Fragment時會發現NestedScrollView會自動向上滾動一段距離;

我第一反應就是有佈局搶焦點了,有時候如果有EdutText也會有類似的現象,解決辦法就是在NestedScrollView裏的唯一佈局設置自動獲取焦點,代碼如下:

<androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#EEEEEE">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="true"//關鍵
                android:focusableInTouchMode="true"//關鍵
                android:orientation="vertical">
             </LinearLayout>
 </androidx.core.widget.NestedScrollView>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章