在自定义控件的构造函数,onLayout(),onFinishInflate()的super方法后面加上if (isInEditMode()) { return; }即可。
见下面代码
public custom_checkbox(Context context) {
super(context);
if (isInEditMode()) { return; }
}
public custom_checkbox(Context context, AttributeSet attrs) {
super(context, attrs);
initCheckboxBitmap();
if (isInEditMode()) { return; }
}
public custom_checkbox(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) { return; }
}
protected void onFinishInflate() {
super.onFinishInflate();
if (isInEditMode()) { return; }
}
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (isInEditMode()) { return; }
}