在Fragment中使用NestedScrollView嵌套RecyclerView时,如果来回切换Fragment就可能会造成界面直接滑动到Recyclerview的第一个Item。
解决方案:
在NestedScrollView的第一个父布局中添加如下属性,强制获得焦点
android:descendantFocusability="blocksDescendants" android:focusable="true" android:focusableInTouchMode="true"
本文介绍如何在Fragment中嵌套NestedScrollView时避免RecyclerView切换时意外滚动,通过在NestedScrollView的首级布局上设置`descendantFocusability`和焦点属性,确保焦点控制的正确性。
在Fragment中使用NestedScrollView嵌套RecyclerView时,如果来回切换Fragment就可能会造成界面直接滑动到Recyclerview的第一个Item。
解决方案:
在NestedScrollView的第一个父布局中添加如下属性,强制获得焦点
android:descendantFocusability="blocksDescendants" android:focusable="true" android:focusableInTouchMode="true"

被折叠的 条评论
为什么被折叠?