package com.mjsheng.myappstore.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.GridView;

// 一个gridview 主要绘制了边界
public class MyGridView extends GridView {

    public boolean isOnMeasure = false;
    private Paint mPaint;


    public MyGridView(Context context) {
        super(context);
        init();
    }

    public MyGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(10);
        mPaint.setColor(Color.parseColor("#ffffff"));
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.dispatchDraw(canvas);
//	    int column = getNumColumns();
//	    int childCount = getChildCount();
//	    for(int i = 0;i < childCount; i++) {
//	        View cellView = getChildAt(i);
//	        if (i % column == 0) {//绘制左边界线
//	           canvas.drawLine(cellView.getLeft(), cellView.getTop(), cellView.getLeft(), cellView.getBottom(), mPaint);
//	        }
//	        //绘制有边界线
//	        canvas.drawLine(cellView.getRight(), cellView.getTop(), cellView.getRight(), cellView.getBottom(), mPaint);
//	        //绘制底边线
//	        canvas.drawLine(cellView.getLeft(), cellView.getBottom(), cellView.getRight(), cellView.getBottom(), mPaint);
//	    }
    }
}
