Skip to content

Instantly share code, notes, and snippets.

@burntcookie90
Created January 27, 2015 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burntcookie90/829fb37bafcfc5fb4fc4 to your computer and use it in GitHub Desktop.
Save burntcookie90/829fb37bafcfc5fb4fc4 to your computer and use it in GitHub Desktop.
add margins to recyclerview items
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private final int mSpace;
public SpacesItemDecoration(int space) {
this.mSpace = space;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = mSpace;
outRect.right = mSpace;
outRect.bottom = mSpace;
// Add top margin only for the first item to avoid double space between items
if(parent.getChildPosition(view) == 0)
outRect.top = mSpace;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment