问题描述
|
有人可以建议我如何使用画布方法绘制圆环吗?我可以用ѭ0来画圆圈,但是我应该如何感觉它们之间有空隙?
解决方法
您可以使用粗笔刷绘制一个圆(使用setStrokeWidth)。
您可以画两个圆,一个在另一个内。一个充满“环”颜色,另一个(内部)充满屏幕“背景颜色”
,在Kotlin中,您可以执行以下操作:
使用init块的笔触样式定义您的绘画
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
}
}
通过使用drawCircleFunction(centerX,centerY,radius,paint)在onDraw方法中绘制圆
override fun draw(canvas: Canvas?) {
super.draw(canvas)
canvas?.drawCircle(width / 2.0f,height / 2.0f,(width - 10) / 2.0f,ringPaint)
}