自定义View
class MyView : View {
private var whitePaint: Paint? = null
private var blackPaint: Paint? = null
private var degrees = 0f
constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
initPaints()
}
private fun initPaints() {
whitePaint = Paint()
whitePaint?.color = Color.WHITE
blackPaint = Paint(whitePaint)
whitePaint?.color = Color.BLACK
}
@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas?) {
val width = wid