7

I have a Recyclerview with GridLayoutManager whose child items may have a vertical RecyclerView inside it. Here is the screenshot:

enter image description here

I have created adapters for this scenario. It shows it properly but internal Recyclerview is not scrolling no matter how many items are inside it. Can anyone suggest how to make internal and main RecyclerViews scroll?

Khawar Raza
  • 15,870
  • 24
  • 70
  • 127

1 Answers1

30

I found the solution. I just had to disable the touch event of the parent in case Recyclerview receives touch event. Here is the code snippet that worked for me:

RecyclerView.OnItemTouchListener mScrollTouchListener = new RecyclerView.OnItemTouchListener() {
    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
        int action = e.getAction();
        switch (action) {
            case MotionEvent.ACTION_MOVE:
                rv.getParent().requestDisallowInterceptTouchEvent(true);
                break;
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {

    }

    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

    }
}; 

recyclerView.addOnItemTouchListener(mScrollTouchListener);

I found the answer here: Recyclerview inside Scrollview

Community
  • 1
  • 1
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
  • 3
    This one is for the child view to apply. Worked like a charm. – Fattum Apr 27 '17 at 16:01
  • Even if you scroll vertically after touching an item, it is still located in the scope of the horizontal scroll. – 최봉재 May 04 '17 at 06:34
  • 1
    It will prevent parent to scroll after you have started scrolling child – Cyph3rCod3r Feb 04 '20 at 11:58
  • this is great. But i need to pause my finger a bit in the childrecyclerview so i can scroll it. So i change MotionEvent.ACTION_MOVE to MotionEvent.ACTION_DOWN, and it works better – zihadrizkyef Mar 15 '23 at 09:51