canvas.drawCircle什么都没画

时间:2015-06-24 18:13:45

标签: java android view draw

这是我对绘图的看法:

@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);
}

但是当我打电话给drawCircle时,它并没有在视图上画任何东西,我不知道为什么......你知道我是否必须在某个地方打电话?

1 个答案:

答案 0 :(得分:0)

@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);
}

删除您制作的drawcircle方法。 我不认为你需要super.onDraw()reason 你不需要this.canvas = canvas;