Skip to content

Instantly share code, notes, and snippets.

@jpetitto
Created January 23, 2017 19:08
Show Gist options
  • Save jpetitto/573bba1025c50ce6cb0f096ead625e44 to your computer and use it in GitHub Desktop.
Save jpetitto/573bba1025c50ce6cb0f096ead625e44 to your computer and use it in GitHub Desktop.
public class SpacingItemDecoration extends RecyclerView.ItemDecoration {
private int spacing;
public SpacingItemDecoration(Context context, int padding) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
spacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padding, metrics);
}
@Override
public final void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
if (position != state.getItemCount() - 1) {
outRect.bottom = spacing;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment