Reputation: 7916
Can anybody suggest me how to draw a ring using canvas methods. I may draw to circles using canvas.drawCircle()
but how should I feel a space between them?
Upvotes: 9
Views: 10438
Reputation: 8705
In kotlin you can do:
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)
}
Upvotes: 2
Reputation: 10507
Upvotes: 23