androidimagestaggeredgridlayoutmanager

How to arrange multiple images horizontally on single activity


I am new to android i have developed an application in which i have to display images horizontal view on single activity i have done using staggered recycleview but am getting like this.

enter image description here

But i want to design like this as part of the activity.

enter image description here


Solution

  • You can easily do that with GridLayoutManager. Use SpanSizeLookup to control your row/column . For your case you have to use HORIZONTAL orientation. SpanSizeLookup will help you to control your rows in each column in HORIZONTAL GridLayoutManager.

     GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), NUM_OF_ROW, LinearLayoutManager.HORIZONTAL, reverseOrder);
    
        GridLayoutManager.SpanSizeLookup spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                  // for position 0 use only one row. for this position it will take all rows
                if (position  == 0) {
                     return NUM_OF_ROW;
                }
    
                return 1;
            }
    };
    

    Here is blog post about different Layout Manager implementation.

    I have uploaded a repo on Github about different LayoutManager usage like LinearLayoutManager, GridLayoutManager, StaggeredGridLayoutManager and some advance RecyclerView usage like swipe, Drag and Drop. You can also check that