什么也没画,甚至调用函数。
我尝试过:
1.将super.onDraw(canvas)移至onDraw的开头和结尾
2.用draw(canvas)替换
3.动态和静态地创建我的视图(我的意思是,用XML)
4.添加setWillNotDraw(false)
class GameView(context: Context) : View(context) {
init {
setWillNotDraw(false) // doesn't change anything
setBackgroundColor( Color.DKGRAY ) // this actually works, but onDraw is not, why?
}
private val ballPaint = Paint(ANTI_ALIAS_FLAG).apply {
color = 0xfefefe
style = Paint.Style.FILL
}
override fun onDraw(canvas: Canvas?) {
println("Test") // printed!
canvas!!.apply {
drawCircle((width/2).toFloat(), (height/2).toFloat(), 100.0f, ballPaint )
}
super.onDraw(canvas)
}
}
我在做什么错了?
答案 0 :(得分:0)
感谢pskink,这就是问题所在
color = 0xfffefefe.toInt()