标签:extend 定义 this 自定义 extends 代码 new ext 构造函数
public class MyCustomView extends View {
//第一个构造函数
public MyCustomView(Context context) {
this(context, null);
}
//第二个构造函数
public MyCustomView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
//第三个构造函数
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO:获取自定义属性
}
....
}
关于三个构造函数使用时机的说法
也就是说,系统默认只会调用Custom View的前两个构造函数,至于第三个构造函数的调用,通常是我们自己在构造函数中主动调用的(例如,在第二个构造函数中调用第三个构造函数).
标签:extend 定义 this 自定义 extends 代码 new ext 构造函数
原文地址:http://www.cnblogs.com/ganchuanpu/p/6746273.html