小编use*_*689的帖子

什么原因导致调用View的OnDraw方法以及何时调用

我在android的Textview类中看到了这个:

@Override
protected void onDraw(Canvas canvas) {
    restartMarqueeIfNeeded();

    // Draw the background for this view
    super.onDraw(canvas);
Run Code Online (Sandbox Code Playgroud)

Viewandroid类中,我看到它是空的:

/**
 * Implement this to do your drawing.
 *
 * @param canvas the canvas on which the background will be drawn
 */
protected void onDraw(Canvas canvas) {
}
Run Code Online (Sandbox Code Playgroud)

如果它是空的,为什么有人会调用超级类的方法呢?

使用参数canvas调用的方法在哪里?

参数画布是由android系统自动传递的吗?

什么时候提取方法叫谁?

当它被覆盖时,是否调用了子类的方法而不是超类'?

这是我的自定义视图,例如:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MyView(this));


    }
}
class MyView extends View {


    public MyView(Context context) {
        super(context); …
Run Code Online (Sandbox Code Playgroud)

java android super android-view

5
推荐指数
1
解决办法
1523
查看次数

标签 统计

android ×1

android-view ×1

java ×1

super ×1