Skip to content

Instantly share code, notes, and snippets.

@kassim
Created September 13, 2017 15:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kassim/582888fa5960791264fc92bc41fb6bcf to your computer and use it in GitHub Desktop.
Save kassim/582888fa5960791264fc92bc41fb6bcf to your computer and use it in GitHub Desktop.
Adds padding to the bottom of a RecyclerView's contents
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class BottomPaddingDecoration extends RecyclerView.ItemDecoration {
private final int bottomPadding;
public BottomPaddingDecoration(int bottomPadding) {
this.bottomPadding = bottomPadding;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
if (position == parent.getAdapter().getItemCount() - 1) {
outRect.set(0, 0, 0, bottomPadding);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment