Create a RecyclerView with horizontal and vertical scrolling at the same time

2

A few weeks ago I am learning to use the RecyclerView . My main intention to learn how to use it, was that I needed to implement a horizontal list, that is, when turning the device in landscape mode (horizontal) it appeared as follows:

After much searching, I found the detailed way to implement it (how to create the horizontal offset of RecyclerView , here ), but I ran into another problem. The item of RecyclerView was larger than the height of the device (in landscape, horizontal), so I need to create a vertical and horizontal scroll at the same time.

I have looked at the Android Developer methods of the LayoutManager class, but my knowledge is not so high as to understand most of the methods that exist, I have also tried to insert another RecyclerView horizontally in a vertical RecyclerView the content, but I get error of IllegalStateException: RecyclerView has no LayoutManager that I found, as a solution, remove all <View.../> of the XML file, but it does not give any results, and of course, I searched through thousands of pages of the Internet, but see that no one has raised this or it is not possible.

To clarify what I ask with this entry is, someone tell me if this is possible and if you have a possible idea of how to implement it (although I do not know if it is possible) and if it is not possible for me to explain why.

    
asked by Vicky Vicent 04.04.2016 в 18:22
source

2 answers

1

I was so angry about all the problems I had with the application that I had not thought about the simplest solution.

It turns out that a RecyclerView is made up of two XML files, a main one where the RecyclerView is declared and another with the content of that RecyclerView item.

The simplest and dumbest solution was to enter the RecyclerView into a ScrollView. This way I can move all the items at once vertically thanks to the ScrollView and I can also move the items horizontally thanks to the RecyclerView in landscape mode.

I leave here the main file of the RecyclerView as it shows:

activity_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/cardIn_margin_ext">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbarStyle="outsideInset"
            android:scrollbars="horizontal" />

</ScrollView>
    
answered by 05.04.2016 / 10:54
source
1

Of course it is possible, what you have to do is what you have researched, create a LinearLayoutManager horizontal that will contain RecyclerView :

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myListHorizontal = (RecyclerView) findViewById(R.id.my_recycler_view_horizontal);
myList.setLayoutManager(layoutManager);

which are the views that would be recycled Horizontally:

and within each horizontal element add a RecyclerView ,

RecyclerView verticalRecyclerView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.my_recycler_view_vertical, null);
verticalRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
addView(verticalRecyclerView);

that will contain views that would be recycled vertically:

    
answered by 04.04.2016 в 19:46