ScrollView中的Horizo​​ntal RecyclerView:垂直滚动时如何获得焦点?

Giu*_*ppo 2 android scrollview horizontal-scrolling android-recyclerview nestedscrollview

我有一个带有多个水平RecyclerView的ScrollView。问题是这样的:
当我垂直滚动以导航到我的应用程序时,当我触摸一个recyclerview进行水平滚动时,焦点仍然停留在滚动视图上,而我无法水平滚动。我必须松开手指并再次触摸才能垂直滚动。
我想赋予recyclerview适当的属性,这样我就可以水平滚动而不停止垂直滚动。

我尝试了多种解决方案:

  • 在recyclerview及其容器的xml中编辑一些参数(focusable,focusableintouchmode,descantantFocusability,nestedscrollingenabled)

  • 在scrollview和recyclerview中都添加一个ontouchlistener并拦截motionevent,

    使用ScrollView和NestedScrollview以及同时使用RecyclerView和ListView都会出现此问题

    谢谢你的帮助

  • ani*_*ind 5

    由于recyclerView,此问题具有默认焦点。只需添加此

    android:descendantFocusability="blocksDescendants"
    
    Run Code Online (Sandbox Code Playgroud)

    到您的scrollView的立即布局。