我正在尝试使用 canvas.drawArc() 方法和将 STROKE 设置为样式的 Paint 创建一个粗的 (~40dp) 分区圆。
但是这个 onDraw() 实现
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.BLUE);
p.setStrokeWidth(getResources().getDimension(R.dimen.circle_stroke_width));
p.setStyle(Paint.Style.STROKE);
RectF rect = new RectF(
getWidth()*0.1f,
getWidth()*0.1f+200,
getWidth()*0.9f,
getWidth()*0.9f+200
);
canvas.drawArc(rect, 0, 180, false, p);
canvas.drawArc(rect, 180, 180, false, p);
}
给了我这个结果
Link to the result picture because I don't have any reputation yet
使用此方法连接多个弧时,有没有办法防止这些间隙?
最佳答案
我也有类似的问题。在 Android Studio 预览窗口中,我的自定义 View 绘制得很好,但在运行 Android 5.0.2 的 HTC One M8 上运行时,在 0 度处出现了轻微的间隙。
我将 View 设置为使用软件渲染,它解决了问题:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
硬件渲染: 软件渲染:
关于android - canvas.drawArc() 使用 Stroke Paint 非常不精确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16774081/