Skip to content

Instantly share code, notes, and snippets.

@abarza
Created September 28, 2016 20:52
Show Gist options
  • Save abarza/9428e59993b18b15ca5eb00b4117a51e to your computer and use it in GitHub Desktop.
Save abarza/9428e59993b18b15ca5eb00b4117a51e to your computer and use it in GitHub Desktop.
Add extra bottom space to the last item in a RecyclerView in order to avoid overlap information with the FloatingActionButton
public class BottomDecoratorHelper extends RecyclerView.ItemDecoration {
private final int bottomOffset;
public BottomDecoratorHelper(int bottomOffset) {
this.bottomOffset = bottomOffset;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
int dataSize = state.getItemCount();
int position = parent.getChildPosition(view);
if (dataSize > 0 && position == dataSize - 1) {
outRect.set(0, 0, 0, bottomOffset);
} else {
outRect.set(0, 0, 0, 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment