Giuseppe Giacoppo
Giuseppe Giacoppo

Reputation: 435

Horizontal RecyclerView inside ScrollView: how to get focus when vertical scrolling?

I have a ScrollView with multiple horizontal RecyclerView. The problem is this:
When I scroll vertically to navigate into my app and I touch on a recyclerview to scroll horizontally, the focus remain on the scrollview and I can't scroll horizontally. I have to release the finger and touch again in order to scroll vertically.
I'd like to give proprity to the recyclerview, so I can scroll horizontally without stopping the vertical scroll.

I tried multiples solutions:

  • editing some parameters in the xml of the recyclerview and its container (focusable, focusableintouchmode, descendantFocusability,nestedscrollingenabled)

  • adding an ontouchlistener and intercepting the motionevent, both in scrollview and recyclerview

    This problem is present using both ScrollView and NestedScrollview and using both RecyclerView and ListView

    Thanks for your help

    Upvotes: 2

    Views: 1896

  • Answers (1)

    Abhinav Suman
    Abhinav Suman

    Reputation: 992

    This problem because of recyclerView has default focus. Just Add this

    android:descendantFocusability="blocksDescendants"
    

    to your immediate layout of scrollView.

    Upvotes: 5

    Related Questions