content: package jp.android.aakira.sample.expandablelayout.util;
  
  import android.content.Context;
  import android.content.res.TypedArray;
  import android.graphics.Canvas;
  import android.graphics.Rect;
  import android.graphics.drawable.Drawable;
  import android.support.v7.widget.RecyclerView;
  import android.view.View;
  
  public class DividerItemDecoration extends RecyclerView.ItemDecoration {
  
      private static final int[] ATTRS = new int[]{
              android.R.attr.listDivider
      };
  
      private Drawable mDivider;
  
      public DividerItemDecoration(final Context context) {
          final TypedArray a = context.obtainStyledAttributes(ATTRS);
          mDivider = a.getDrawable(0);
          a.recycle();
      }
  
      @Override
      public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
          super.onDrawOver(c, parent, state);
          final int left = parent.getPaddingLeft();
          final int right = parent.getWidth() - parent.getPaddingRight();
  
          final int childCount = parent.getChildCount();
          for (int i = 0; i < childCount; i++) {
              final View child = parent.getChildAt(i);
              final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                      .getLayoutParams();
              final int top = child.getBottom() + params.bottomMargin;
              final int bottom = top + mDivider.getIntrinsicHeight();
              mDivider.setBounds(left, top, right, bottom);
              mDivider.draw(c);
          }
      }
  
      @Override
      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
          super.getItemOffsets(outRect, view, parent, state);
  
          outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
      }
  }
  