Created
September 28, 2016 20:52
-
-
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
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 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