Created
January 23, 2017 19:08
-
-
Save jpetitto/573bba1025c50ce6cb0f096ead625e44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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