实现某个功能时发现RecyclerView总是先获取焦点,然后在ScrollView中滑动,为了让ScrollVoiew先滑动,我尝试了网上一些博客所说的方法,有些博主能成功,而我的却啊还是不行,具体列出尝试的几种方法:
1. 在ScrollView中添加属性(已经设有属性android:fillViewport="true"):
android:focusable="true"
android:focusableInTouchMode="true"
2.给RecyclerView添加外布局,RelativeLayout,并且设置属性:
android:descendantFocusability="blocksDescendants"
3.在ScrollView中添加属性:
android:descendantFocusability="beforeDescendants"
#这里顺带提一下 android:descendantFocusability="blocksDescendants",该属性是当一个View获取焦点时,定义ViewGroup与子控件直接的关系,常用来解决父控件的焦点或者点击事件被子控件获取,属性值有三种:
1)beforeDescendants :ViewGroup先于子控件获取焦点;
2)afterDescendants: ViewGroup只有当子控件不需要获取焦点时获取焦点;
3)blocksDescendants: ViewGroup会覆盖子控