canvas.drawCircle draw nothing

242 Views Asked by At

This is my view for drawing :

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    this.canvas = canvas;
    canvas.drawCircle(this.getWidth()/2,this.getHeight()/2,100, locationPaint);
    canvas.drawCircle(this.getWidth()/2,this.getHeight()/2,300, locationPaint);
    //canvas.drawRect(this.getWidth()/2,this.getHeight()/2,100,100, locationPaint);
}

public void drawCircle(float centerX, float centerY, float width, float height){
    int ratio = 10;
    canvas.drawCircle(centerX/ratio,centerY/ratio,width/ratio,circlePaint);
    canvas.drawCircle(this.getWidth()/2,this.getHeight()/2,200, locationPaint);
}

But when i call drawCircle, it didn't draw nothing on the view, i don't know why... Do you know if i have to call onDraw somewhere ?

1

There are 1 best solutions below

0
On
@Override
protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
    canvas.drawCircle(this.getWidth/2, this.getHeight/2, 100, locationPaint();
    canvas.drawCircle(this.getWidth()/2,this.getHeight()/2,300, locationPaint);
}

Delete your drawcircle method that you made. I don't think that you need super.onDraw() reason You don't need this.canvas = canvas;