填充自定义视图画布

时间:2014-04-07 13:51:55

标签: android canvas

我是android的新手,我有一个问题(可能是假问题......) 我通过扩展View元素来创建自定义视图。

我开始绘制并注意到我的绘图在顶部和左边界处被剪裁了一点。

我该怎么做才能解决它? enter image description here

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec){
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int chosenDimention = Math.min(widthSize, heightSize);
        setMeasuredDimension(chosenDimention, chosenDimention);
        Log.v(TAG, "onMeasure: "+chosenDimention);
    }

public void onDraw(Canvas canvas){

        drawBackground(canvas);
        Log.v(TAG, "onDraw");
        Canvas c = new Canvas(background);
        drawPie(c);


    }

private void drawPie(Canvas canvas){
        int width = getWidth();
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale(width, width);
// drawing stuff

        canvas.restore();
    }

0 个答案:

没有答案