我正在尝试绘制一条弧线以覆盖在现有圆的某些部分之上。我的两个圆圈都画得很好,但我的 drawArc() 调用或 drawRect() 调用似乎都没有做任何事情。该应用程序不会崩溃,也不例外。它只是默默地失败。
onDraw() 代码:
@Override
protected void onDraw(Canvas canvas) {
int width = getWidth();
int height = getHeight();
int size = (width > height) ? height : width;
float cx = width / 2;
float cy = height / 2;
float radius = size / 2;
float left = cx - radius;
float right = cx + radius;
float top = cy - radius;
float bottom = cy + radius;
RectF rect = new RectF(left, top, right, bottom);
RectF rect2 = new RectF(canvas.getClipBounds());
Log.d("MyTag", "Left: " + rect.left + "Right: " + rect.right + "Top: " + rect.top + "Bottom: " + rect.bottom);
Log.d("MyTag", "Left: " + rect2.left + "Right: " + rect2.right + "Top: " + rect2.top + "Bottom: "
+ rect2.bottom);
canvas.drawCircle(cx, cy, radius, circleRing);//Works
canvas.drawCircle(cx, cy, radius - barWidth, innerColor);//Works
canvas.drawArc(rect, 0, angle, true, circleColor);//Doesn't work
canvas.drawRect(rect, circleColor);//Doesn't work
super.onDraw(canvas);
}
我已经确认我的circleColor
Paint 设置正确,这angle
是一个弧线的有效值。
我的油漆在 {} 块中设置如下,以便所有构造函数都使用它:
{
circleColor = new Paint();
innerColor = new Paint();
circleRing = new Paint();
circleColor.setColor(color.holo_blue_light);
innerColor.setColor(Color.BLACK);
circleRing.setColor(Color.GRAY);
circleColor.setAntiAlias(true);
innerColor.setAntiAlias(true);
circleRing.setAntiAlias(true);
circleColor.setStrokeWidth(50);
innerColor.setStrokeWidth(5);
circleRing.setStrokeWidth(5);
circleColor.setStyle(Paint.Style.FILL);
}
我试过的:
- 硬编码坐标
- 使用圆圈使用的颜料
- 只有 drawArc() 调用存在并注释掉其余的平局
- 禁用硬件加速
Logcat 显示我的 RectF 具有有效点,只是顶部和底部缩放以形成一个正方形:
01-25 13:33:39.877: D/MyTag(21612): Left: 0.0 Right: 720.0 Top: 159.0 Bottom: 879.0 //Mine
01-25 13:33:39.877: D/MyTag(21612): Left: 0.0 Right: 720.0 Top: 0.0 Bottom: 1038.0 //Canvas'
有人知道是什么原因造成的吗?