[英]How to draw a ring using canvas in android?
Can anybody suggest me how to draw a ring using canvas methods.谁能建议我如何使用 canvas 方法画一个环。 I may draw to circles using
canvas.drawCircle()
but how should I feel a space between them?我可以使用
canvas.drawCircle()
绘制圆圈,但我应该如何感觉到它们之间的空间?
In kotlin you can do:在 kotlin 你可以这样做:
class CustomView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var ringPaint: Paint
init {
ringPaint = Paint()
ringPaint.color = R.color.RED // Your color here
ringPaint.style = Paint.Style.STROKE // This is the important line
ringPaint.strokeWidth = 20f // Your stroke width in pixels
}
}
override fun draw(canvas: Canvas?) {
super.draw(canvas)
canvas?.drawCircle(width / 2.0f, height / 2.0f, (width - 10) / 2.0f, ringPaint)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.