-2

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

mehul chauhan
  • 1,792
  • 11
  • 26
santosh
  • 15
  • 6

2 Answers2

2

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

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
0

here is what i use for arranging items horizontally provided you're using RecyclerView:

 int numberOfColumns = 3; //edit as you want pls
        final GridLayoutManager gridLayoutManager = new GridLayoutManager(this.getContext(), numberOfColumns);
        recyclerView.setLayoutManager(gridLayoutManager);
        recyclerView.setAdapter(adapter);

I might be off your solution, perdon if so, but pasting some of your code might help better.

Wale
  • 1,644
  • 15
  • 31
  • StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, LinearLayoutManager.HORIZONTAL); recyclerViewStaggered.setLayoutManager(staggeredGridLayoutManager); StaggeredAdapter customAdapter = new StaggeredAdapter(getActivity(), personImages); recyclerViewStaggered.setAdapter(customAdapter); – santosh Aug 27 '18 at 08:44
  • If orientation is vertical, spanCount is number of columns. If orientation is horizontal, spanCount is number of rows. I don't think you notice this??? Apparently your code is set! and this all you need to do: change HORIZONTAL to VERTICAL – Wale Aug 27 '18 at 09:43
  • What about span count then? shall i use it or not – santosh Aug 27 '18 at 10:07
  • yes you need span count! it helps set how many pictures will be displayed in columns after which the rest of the pictures will go to the next row. – Wale Aug 28 '18 at 09:53