gpt4 book ai didi

android - canvas.drawArc() 使用 Stroke Paint 非常不精确

转载 作者:行者123 更新时间:2023-11-29 00:29:26 27 4
gpt4 key购买 nike

我正在尝试使用 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 绘制得很好,但在我的 HTC One M8 和 Android 5.0.2 上运行它时,在 0 度处出现了轻微的差距。

我将 View 设置为使用软件渲染并解决了这个问题:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

硬件渲染:软件渲染:

gap no gap

关于android - canvas.drawArc() 使用 Stroke Paint 非常不精确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16774081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com