Canvas does not draw in Custom View

*爱你&永不变心* 提交于 2019-12-01 02:59:18

Your onDraw method is never called, you need to call setWillNotDraw(false) on the constructor of your Custom View in order to get onDraw actually called.

As stated on Android SDK:

If this view doesn't do any drawing on its own, set this flag to allow further optimizations. By default, this flag is not set on View, but could be set on some View subclasses such as ViewGroup. Typically, if you override onDraw(android.graphics.Canvas) you should clear this flag.

Where is your this.draw() method?

This should work definitively:

protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);         
    canvas.drawCircle(50, 50, 25, paint1);
    //this.draw(canvas);  where is this method?
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!