正常状况下,因为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"