Do I need to call back super.onDraw() in a custom view?

后端 未结 4 1824
情歌与酒
情歌与酒 2021-02-07 06:35

I\'m not too clear about this and neither are the docs.

When I\'m creating a custom view, I override like so:

@Override
public void onDraw(Canvas canvas)         


        
4条回答
  •  一生所求
    2021-02-07 06:41

    If you want it to call the superclass onDraw method (think TextView or KeyboardView rather than a generic View), then call super.onDraw. If you don't want that, i.e. you are planning on drawing the entire View yourself (which it seems you are), there's no reason to call it.

    Also, if you're extending View (and not some class that extends view), super.onDraw doesn't really do anything.

    For me, I call super.onDraw when I want to draw lines over a KeyboardView. So, super.onDraw draws the keyboard, and my custom LatinKeyboardView (which extends KeyboardView) draws the swiping path on top of the keyboard.

提交回复
热议问题