Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RecyclerView inside RecyclerView is not scrolling

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?

like image 941
Khawar Raza Avatar asked Mar 17 '17 13:03

Khawar Raza


People also ask

Is RecyclerView scrollable?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .

What is Nested scrolling in RecyclerView?

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child. In your case you have to define your own scrolling behaviour.

How can show all items in RecyclerView without scrolling?

It's pretty simple, simply set the RecyclerView 's height to wrap_content . That's right.

What is the difference between RecyclerView and ScrollView?

In the practical on scrolling views, you use ScrollView to scroll a View or ViewGroup . ScrollView is easy to use, but it's not recommended for long, scrollable lists. RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists.


1 Answers

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

like image 154
Khawar Raza Avatar answered Sep 28 '22 07:09

Khawar Raza