Skip to content

Instantly share code, notes, and snippets.

@skylee91
Forked from polbins/README.md
Created October 1, 2015 11:20
Show Gist options
  • Select an option

  • Save skylee91/1831b1230bfe0da66153 to your computer and use it in GitHub Desktop.

Select an option

Save skylee91/1831b1230bfe0da66153 to your computer and use it in GitHub Desktop.

Revisions

  1. @polbins polbins revised this gist Mar 5, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion SimpleDividerItemDecoration.java
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ public SimpleDividerItemDecoration(Context context) {
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

  2. @polbins polbins created this gist Jan 6, 2015.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    #### Simple RecyclerView Divider

    Simple Horizontal Divider Item Decoration for RecyclerView

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(
    getApplicationContext()
    ));
    _NOTE:_ Add item decoration prior to setting the adapter
    26 changes: 26 additions & 0 deletions SimpleDividerItemDecoration.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration {
    private Drawable mDivider;

    public SimpleDividerItemDecoration(Context context) {
    mDivider = context.getResources().getDrawable(R.drawable.line_divider);
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
    View child = parent.getChildAt(i);

    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

    int top = child.getBottom() + params.bottomMargin;
    int bottom = top + mDivider.getIntrinsicHeight();

    mDivider.setBounds(left, top, right, bottom);
    mDivider.draw(c);
    }
    }
    }
    11 changes: 11 additions & 0 deletions line_divider
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <size
    android:width="1dp"
    android:height="1dp" />

    <solid android:color="@color/dark_gray" />

    </shape>