NestedScrollView嵌套RecyclerView,Recyclerview占据焦点导致整个NestedScrollView内容上滑

576 阅读1分钟

方法一:在根布局设置android:descendantFocusability=”blocksDescendants” ;根布局不能是NestedScrollView

android:descendantFocusability 有三种值:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

这种方法,会造成页面中Editext焦点被抢导致无法输入,需要用到第二种方法。 方法二:对于有Editext的页面需要在根布局使用 :

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

方法三:在NestedScrollView顶部第一个控件使用 :

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