Created
September 13, 2017 15:59
-
-
Save kassim/582888fa5960791264fc92bc41fb6bcf to your computer and use it in GitHub Desktop.
Adds padding to the bottom of a RecyclerView's contents
This file contains hidden or 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
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