作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最佳答案
我认为您可以通过绘制三条部分重叠的线来解决此问题:
Paint.Cap.ROUND
的外线Paint.Cap.BUTT
的内线假设你的输入数据是
float lineWidth = 20;
float lineRadius = 100;
float cornerRadius = 2;
你走如下,
float width, radius;
// Draw outer lines
paint.setStrokeCap(Paint.Cap.ROUND);
width = cornerRadius * 2;
// Draw inner
radius = lineRadius - lineWidth/2f + cornerRadius;
canvas.draw(...)
// Draw outer
radius = lineRadius + lineWidth/2f - cornerRadius;
canvas.draw(...)
// Draw center
paint.setStrokeCap(Paint.Cap.BUTT);
width = lineWidth - 2f*cornerRadius;
radius = lineRadius;
canvas.draw(...)
您可能需要稍微改变中心线的弧角(每边必须 cornerRadius
更长)但这很容易。
关于Android:如何画圆角线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43483865/
我是一名优秀的程序员,十分优秀!