Removing the default interval in the recycler view layout

I am using the StaggeredGridLayout manager to view the recycler

 mStaggerGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager .VERTICAL); 

Now I want to remove the spacing between columns and rows. Something like this image, but with only two columns.

enter image description here

+5
source share
1 answer

You need to play with margin. Not filling out.

StaggeredGridLayoutManager sets the default value to "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; } } 
+1
source

Source: https://habr.com/ru/post/1245267/


All Articles