我是否需要再打super.onDraw()的自定义视图? [英] Do I need to call back super.onDraw() in a custom view?

查看:890
本文介绍了我是否需要再打super.onDraw()的自定义视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是太清楚这一点,无论是文档。

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) {
    super.onDraw(canvas);

    //more code here...
}

我的问题是,是否有必要调用 super.onDraw(画布); 。在code似乎做工精细,没有它,但我想,以确保它的好离开它。

My question is whether it's necessary to call super.onDraw(canvas);. The code seems to work fine without it, but I want to be sure that it's okay to leave it out.

因此​​,有必要吗?

推荐答案

如果你想它来调用父类的OnDraw方法(想的TextView或KeyboardView,而不是一个普通视图),然后调用super.onDraw。如果你不希望出现这种情况,即你正在计划绘制整个看待自己(这看来你是),没有理由调用它。

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.

另外,如果你在扩展视图(而不是某个类扩展视图),super.onDraw并没有真正做任何事情。

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

对于我来说,我打电话super.onDraw时,我要画过KeyboardView线。因此,super.onDraw平键盘,和我的自定义LatinKeyboardView(延伸KeyboardView)借鉴了键盘顶部的刷卡路径。

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.

这篇关于我是否需要再打super.onDraw()的自定义视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆