Padding custom view canvas

I'm new to android and I have a question (maybe a dummy question ...) I am creating a custom view by expanding the View element.

I start to draw and notice that my drawings are slightly cropped at the top and left borders.

What should I do to solve this problem? 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();
    }
+4
source share

Source: https://habr.com/ru/post/1535373/


All Articles