package com.philisense.rdgo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
 * Created by shaop on 2017/12/7.
 */

public class MainRecyclerViewDecoration extends RecyclerView.ItemDecoration {

    @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {

        super.onDrawOver(c, parent, state);
        int childCount = parent.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = parent.getChildAt(i);
            int pos = parent.getChildAdapterPosition(child);
            if (pos % 3 == 0) {
                // 左边第一个列不做任何事
            }else if (pos % 3 == 2) {
                // 最右边一列，什么都不做
            }else {
                float left = 1;
                float right = 1;
                float top = child.getTop();
                float bottom = child.getBottom();
                Paint paint = new Paint();
                paint.setColor(Color.GRAY);
                c.drawRect(left, top, right, bottom, paint);
            }

            if (pos / 3 == 0) {
                // 左边第一个列不做任何事
            }else if (pos / 3 == 2) {
                // 最右边一列，什么都不做
            }else {
                float left = child.getLeft();
                float right = child.getRight();
                float top = 1;
                float bottom = 1;
                Paint paint = new Paint();
                paint.setColor(Color.GRAY);
                c.drawRect(left, top, right, bottom, paint);
            }

        }
    }
}