Search code examples
androidandroid-recyclerviewhorizontal-scrolling

Android Horizontal RecyclerView scroll Direction


I made a Horizontal RecyclerView and it works fine(thanks to this) but the direction of scroll and data are expand from left to right; then How can I change the RecyclerView scroll direction like in the picture below?

enter image description here

My Code:

StaggeredGridLayoutManager staggeredGridLayoutManager =
                new StaggeredGridLayoutManager(
                        2, //The number of Columns in the grid
                        LinearLayoutManager.HORIZONTAL);

Solution

  • Assuming you use LinearLayoutManager in your RecyclerView, then you can pass true as third argument in the LinearLayoutManager constructor.

    For example:

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
    

    If you are using the StaggeredGridLayoutManager, then you can use the setReverseLayout method it provides.