Skip to content

Commit 177a2e0

Browse files
committed
[Fix]: #7 Design mode error.
Support design edit mode
1 parent 1ae0bdd commit 177a2e0

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleFrameLayout.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public ScaleFrameLayout(Context context, AttributeSet attrs) {
2424

2525
public ScaleFrameLayout(Context context, AttributeSet attrs, int defStyle) {
2626
super(context, attrs, defStyle);
27-
mHelper = ScaleLayoutHelper.create(this, attrs);
27+
if (!isInEditMode()) {
28+
mHelper = ScaleLayoutHelper.create(this, attrs);
29+
}
2830
}
2931

3032
@Override
@@ -34,13 +36,15 @@ protected LayoutParams generateDefaultLayoutParams() {
3436

3537
@Override
3638
public LayoutParams generateLayoutParams(AttributeSet attrs) {
37-
return new LayoutParams(this.getContext(), attrs);
39+
return new LayoutParams(this.getContext(), attrs, isInEditMode());
3840
}
3941

4042
@Override
4143
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
42-
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
43-
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
44+
if (!isInEditMode()) {
45+
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
46+
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
47+
}
4448

4549
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
4650
// if (this.mHelper.handleMeasuredStateTooSmall()) {
@@ -62,6 +66,13 @@ public LayoutParams(Context c, AttributeSet attrs) {
6266
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
6367
}
6468

69+
private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {
70+
super(c, attrs);
71+
if (!isInEditMode) {
72+
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
73+
}
74+
}
75+
6576
public LayoutParams(int width, int height) {
6677
super(width, height);
6778
}

ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleLinearLayout.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public ScaleLinearLayout(Context context, AttributeSet attrs) {
2727
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
2828
public ScaleLinearLayout(Context context, AttributeSet attrs, int defStyle) {
2929
super(context, attrs, defStyle);
30-
mHelper = ScaleLayoutHelper.create(this, attrs);
30+
if (!isInEditMode()) {
31+
mHelper = ScaleLayoutHelper.create(this, attrs);
32+
}
3133
}
3234

3335
@Override
@@ -37,14 +39,15 @@ protected LayoutParams generateDefaultLayoutParams() {
3739

3840
@Override
3941
public LayoutParams generateLayoutParams(AttributeSet attrs) {
40-
return new LayoutParams(this.getContext(), attrs);
42+
return new LayoutParams(this.getContext(), attrs, isInEditMode());
4143
}
4244

4345
@Override
4446
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
45-
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
46-
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
47-
47+
if (!isInEditMode()) {
48+
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
49+
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
50+
}
4851
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
4952
// if (this.mHelper.handleMeasuredStateTooSmall()) {
5053
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -65,6 +68,13 @@ public LayoutParams(Context c, AttributeSet attrs) {
6568
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
6669
}
6770

71+
private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {
72+
super(c, attrs);
73+
if (!isInEditMode) {
74+
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
75+
}
76+
}
77+
6878
public LayoutParams(int width, int height) {
6979
super(width, height);
7080
}

ScaleLayout/src/main/java/cn/gavinliu/android/lib/scale/ScaleRelativeLayout.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public ScaleRelativeLayout(Context context, AttributeSet attrs) {
2424

2525
public ScaleRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
2626
super(context, attrs, defStyle);
27-
mHelper = ScaleLayoutHelper.create(this, attrs);
27+
if (!isInEditMode()) {
28+
mHelper = ScaleLayoutHelper.create(this, attrs);
29+
}
2830
}
2931

3032
@Override
@@ -34,13 +36,15 @@ protected LayoutParams generateDefaultLayoutParams() {
3436

3537
@Override
3638
public LayoutParams generateLayoutParams(AttributeSet attrs) {
37-
return new LayoutParams(this.getContext(), attrs);
39+
return new LayoutParams(this.getContext(), attrs, isInEditMode());
3840
}
3941

4042
@Override
4143
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
42-
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
43-
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
44+
if (!isInEditMode()) {
45+
this.mHelper.adjustHost(widthMeasureSpec, heightMeasureSpec);
46+
this.mHelper.adjustChildren(widthMeasureSpec, heightMeasureSpec);
47+
}
4448

4549
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
4650
// if (this.mHelper.handleMeasuredStateTooSmall()) {
@@ -62,6 +66,13 @@ public LayoutParams(Context c, AttributeSet attrs) {
6266
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
6367
}
6468

69+
private LayoutParams(Context c, AttributeSet attrs, boolean isInEditMode) {
70+
super(c, attrs);
71+
if (!isInEditMode) {
72+
this.mPercentLayoutInfo = ScaleLayoutHelper.getScaleLayoutInfo(c, attrs);
73+
}
74+
}
75+
6576
public LayoutParams(int width, int height) {
6677
super(width, height);
6778
}

0 commit comments

Comments
 (0)