flexbox-layout
flexbox-layout copied to clipboard
Limit number of items per row/column?
Hello, I am trying to use flexbox-layout with RecyclerView to scroll list with dozens of elements (icons with text). It works mostly fine, but elements would fill the whole available space on screen, but I want to limit number of elements per row (when scroll down) or number of elements per column (when scroll to the right).
I can achieve same thing with GridLayoutManager:
final GridLayoutManager gridLayoutManager = new GridLayoutManager(
getApplicationContext(), 2, GridLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(gridLayoutManager);
but grid layout manager does not allow me to align items by center.
Can I do this with FlexBoxLaout?
Any progress on it?
Any progress on it?
Any progress on it?
You can use layout_wrapBefore
attribute for this I guess. This can be done by sub-classing the FlexboxLayoutManager
class.
@Override
public View getFlexItemAt(int index) {
View item = super.getFlexItemAt(index);
FlexboxLayoutManager.LayoutParams params =
(FlexboxLayoutManager.LayoutParams) item.getLayoutParams();
params.setWrapBefore(index % maxPerRow == 0);
return view;
}
This is a hack, but I don't see any other solution at this point.
You can use
layout_wrapBefore
attribute for this I guess. This can be done by sub-classing theFlexboxLayoutManager
class.@Override public View getFlexItemAt(int index) { View item = super.getFlexItemAt(index); FlexboxLayoutManager.LayoutParams params = (FlexboxLayoutManager.LayoutParams) item.getLayoutParams(); params.setWrapBefore(index % maxPerRow == 0); return view; }
This is a hack, but I don't see any other solution at this point.
thank you, good answer