Created
May 13, 2017 17:00
-
-
Save ThomasStuetz/109991a9f09c531e6a3d7d409a7ce92c to your computer and use it in GitHub Desktop.
Google's sample implementation of dividers displayed between the RecyclerView items
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
@Override | |
public void onDrawOver(Canvas c, RecyclerView parent, | |
RecyclerView.State state) { | |
super.onDrawOver(c, parent, state); | |
// calculate left/right x-coordinates for all dividers | |
int left = parent.getPaddingLeft(); | |
int right = parent.getWidth() - parent.getPaddingRight(); | |
// for every item but the last, draw a line below it | |
for (int i = 0; i < parent.getChildCount() - 1; ++i) { | |
View item = parent.getChildAt(i); // get ith list item | |
// calculate top/bottom y-coordinates for current divider | |
int top = item.getBottom() + ((RecyclerView.LayoutParams) | |
item.getLayoutParams()).bottomMargin; | |
int bottom = top + divider.getIntrinsicHeight(); | |
// draw the divider with the calculated bounds | |
divider.setBounds(left, top, right, bottom); | |
divider.draw(c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment