Ahmed Abdelmeged
Ahmed Abdelmeged

Reputation: 2419

Recycler view with wrap content items horizontal and vertical scroll

hi i want to make a recycler view to take items horizontal as many as the screen fit but with vertical scroll like this image as example

enter image description here

I try with StaggeredGridLayoutManager but it must specify the number of column want the column take as screen size any help will be good

Upvotes: 6

Views: 5500

Answers (2)

Burhanuddin Rashid
Burhanuddin Rashid

Reputation: 5370

You can use FlexLayoutManager for this kind of design FlexLayout

Here is a example snippet to use FlexLayoutManager in RecycleView

RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.COLUMN);
layoutManager.setJustifyContent(JustifyContent.FLEX_END);
recyclerView.setLayoutManager(layoutManager);

Their are many attributes to use FlexLayout Go through the documents on github

Upvotes: 10

Inneke De Clippel
Inneke De Clippel

Reputation: 1026

As Burhanuddin Rashid commented, you should use the FlexBoxLayout. It has a LayoutManager for RecyclerViews, so the additional code will be minimal. https://github.com/google/flexbox-layout#flexboxlayoutmanager-within-recyclerview

Upvotes: -1

Related Questions