I'm using StaggeredGridLayout
manager for recycler view
mStaggerGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager
.VERTICAL);
Now, I want to remove default spacing there is between columns and rows. Something like in this image but with only 2 columns.
You have to play around with margin. Not the padding.
The StaggeredGridLayoutManager sets a default margin of "30dp" for each grid item.
It can be changed as follows,
class StaggeredListDecoration extends RecyclerView.ItemDecoration {
public StaggeredListDecoration() {
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
BaseCard.CARD_TYPE viewType = (BaseCard.CARD_TYPE)view.getTag();
((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).leftMargin = 0;
((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).rightMargin = 0;
((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).topMargin = 0;
((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams()).bottomMargin= 0;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With