有人可以建议我如何使用canvas方法绘制一个环。我可以使用canvas.drawCircle()
绘制圆圈,但我应该如何感受它们之间的空间?
答案 0 :(得分:18)
答案 1 :(得分:0)
在科特林,您可以这样做:
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)
}