Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested RecyclerView like Google Play Store App

I am currently working on replicating the UI pattern implemented in the Play Store App. For implementing such a behavior, I have used a Vertical RecyclerView as outer view and added a horizontal RecyclerView inside the adapter of the outer Vertical RecyclerView.

The problem I am currently facing is while the outer RecyclerView is scrolling, the inner horizontal RecyclerView cannot catch the scroll event on it, but when the outer RecyclerView is not scrolling, we can scroll the horizontal RecyclerView smoothly.

If any one can be helpful please leave your comment. Cou can test the functionality in the Play store it enables the scroll of inner horizontal RecyclerView, even if the outer RecyclerView is scrolling.

Play store app:

link to the image

like image 717
Arslan Sohail Avatar asked Dec 31 '15 17:12

Arslan Sohail


People also ask

Can we use nested RecyclerView in android?

A nested RecyclerView is an implementation of a RecyclerView within a RecyclerView. An example of such a layout can be seen in a variety of apps such as the Play store where the outer (parent) RecyclerView is of Vertical orientation whereas the inner (child) RecyclerViews are of horizontal orientations.

Can we use RecyclerView inside RecyclerView in android?

The RecyclerView widget manages the display and handling of items in a list. It provides Layout Managers to position these items. This way, you can create customized layout managers for RecyclerView containers. We can use a RecyclerView inside another RecyclerView.

Is ListView better than RecyclerView?

Simple answer: You should use RecyclerView in a situation where you want to show a lot of items, and the number of them is dynamic. ListView should only be used when the number of items is always the same and is limited to the screen size.


1 Answers

Here's a tutorial for implementing such RecyclerView. You might also consider looking at the github repository as well.

The idea is to disable the touch detection of the outer RecyclerView when the inner RecyclerView is touched. See the implementation here in the parent RecyclerView adapter class.

// Disable touch detection for parent recyclerView if we use vertical nested recyclerViews
private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
}; 

And then set the touch listener to the view.

view.findViewById(R.id.recyclerView).setOnTouchListener(mTouchListener);
like image 176
Reaz Murshed Avatar answered Oct 19 '22 06:10

Reaz Murshed