padding custom view canvas
NickName:user3319474 Ask DateTime:2014-04-07T21:51:54

padding custom view canvas

I newbie to android and I have a question(probably dummy question ...) I am creating a custom view by extending View element.

I start to draw and notice that my drawings is clipped a little bit at the top and left boundaries.

what should I do to solved it out? 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();
    }

Copyright Notice:Content Author:「user3319474」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22914488/padding-custom-view-canvas

More about “padding custom view canvas” related questions

padding custom view canvas

I newbie to android and I have a question(probably dummy question ...) I am creating a custom view by extending View element. I start to draw and notice that my drawings is clipped a little bit at...

Show Detail

How can I contract canvas by a view padding?

I'm building a custom view, in which I override onDraw method. Is there a way to contract canvas (received as an argument in onDraw) by this view padding values? And to answer any possible questi...

Show Detail

How to set padding in custom view?

In my application I have a custom TextView that has some arrow on the left in onDraw method on Canvas. The problem I have is with gravity of the text, as I want it to be centered. The only way I h...

Show Detail

No padding-effect in custom ImageView

I've got an issue assigning padding-values to my custom ImageView. Please note, that I'm not extending ImageView but View: public class CustomImageView extends View The image is loaded from the a...

Show Detail

Android custom view's padding when scroll

I wrote a custom text view(it doesn't matter what kind of view actually) that extends from View. I added padding to this view in my XML document and read these padding and pass it to super to apply...

Show Detail

Bounce animation for custom view drawn with canvas

I am drawing different view in a custom view with canvas, and want to add custom animation to on of the view (infinite bounce) not sure how this can be achieved. Would appreciate any suggestions. H...

Show Detail

Custom View: Redraw view canvas on Press

I'm working on custom view, which have to draw custom canvas when pressed and other if not. I have basically overriden only methods onMeasure and onDraw. In Constructor I have set: setFocusable(tru...

Show Detail

Canvas does not draw in Custom View

I created a Custom View CircleView like this: public class CircleView extends LinearLayout { Paint paint1; public CircleView(Context context) { super(context); init(); ...

Show Detail

Unable to perform click on a custom view inflated on the top of android Canvas?

I have been trying to build a popup on canvas click, which further has buttons on it. I inflated the popup on the canvas, but when i try clicking on it the popup closes. This is how i am inflating...

Show Detail

Android custom view with canvas

I would like to create a custom bullet points in android using canvas. Following is my code. protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.

Show Detail