paint.drawArc()不绘画

时间:2015-09-02 11:51:12

标签: java android graphics

我正在尝试画一个将分为4种颜色的球:绿色,红色,黄色和蓝色。

有些球只使用一种颜色,所以我这样画它们:

 paint.setColor(color);
 canvas.drawCircle(x, y, ballRadius, paint);

他们出现在屏幕上,这里没有问题。

但是当我尝试着色其他的颜色时,使用相同的油漆和画布对象使用此代码我在屏幕上没有结果:

 RectF rect = new RectF(x - ballRadius, y + ballRadius, x + ballRadius, y - ballRadius);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.GREEN);
    canvas.drawArc(rect, 0, 90, true, paint);
    paint.setColor(Color.RED);
    canvas.drawArc(rect, 90, 180, true, paint);
    paint.setColor(Color.YELLOW);
    canvas.drawArc(rect, 180, 270, true, paint);
    paint.setColor(Color.BLUE);
    canvas.drawArc(rect, 270, 360, true, paint);

1 个答案:

答案 0 :(得分:0)

RectF rect = new RectF(x - ballRadius, y + ballRadius, x + ballRadius, y - ballRadius);

不正确,因为RectF的参数必须按照正确的顺序left, top, right, bottom

  

使用指定的坐标创建一个新矩形。注意:不执行范围检查,因此呼叫者必须确保left <= righttop <= bottom

矩形的正确定义(假设ballRadius > 0!)将是:

RectF rect = new RectF(x - ballRadius, y - ballRadius, x + ballRadius, y + ballRadius);