Horizontal Recyclerview inside vertical scroll

I have a situation where I have a Recyclerview that slides horizontally inside a ScrollView. Now the situation is when I do horizontal scrolling in the Recyclerview, instead of scrolling the maps in the Recyclerview, it scrolls up the screen, which breaks the user experience.

Any solution or approach to avoid vertical scrolling when the person is doing horizontal scrolling in the Recyclerview?

+3


source to share


2 answers


This issue occurs because of scroll_conflicts As Frank said. But I sometimes realize that we need to go beyond Design guidelines. By the way, you can disallow the ScrollView (I'm taking it as the parent of the RecyclerView) to catch any touch events. Below is a sample code for this.

mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    int action = event.getAction();
                    switch (action) {
                        case MotionEvent.ACTION_DOWN:
                            // Disallow ScrollView to intercept touch events.
                            v.getParent().requestDisallowInterceptTouchEvent(true);
                            break;
                        case MotionEvent.ACTION_UP:
                            //Allow ScrollView to intercept touch events once again.
                            v.getParent().requestDisallowInterceptTouchEvent(false);
                            break;
                    }
                    // Handle RecyclerView touch events.
                    v.onTouchEvent(event);
                    return true;
                }
            });

      



Hope this works for your problem. But check LayoutManager first. I think there is no need for the code above if you are explicitly using the LinearLayoutManager with a HORIZONTAL layout.

+4


source


The solution is actually pretty simple. put horizontal RecycleView as element in RecycleView instead of using scrollview. then when scrolling it behaves the way you want it to. What i did and works great



+1


source







All Articles