【发布时间】:2012-03-01 00:42:24
【问题描述】:
在创建自定义视图时,我注意到很多人似乎是这样操作的:
public MyView(Context context) {
super(context);
// this constructor used when programmatically creating view
doAdditionalConstructorWork();
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
// this constructor used when creating view through XML
doAdditionalConstructorWork();
}
private void doAdditionalConstructorWork() {
// init variables etc.
}
我的第一个问题是,构造函数MyView(Context context, AttributeSet attrs, int defStyle) 呢?我不确定它在哪里使用,但我在超类中看到它。我需要它吗?它在哪里使用?
【问题讨论】:
标签: android android-custom-view