Skip to content

Commit 89d6a69

Browse files
fix(ADFA-2872): Set default layout params values (#1158)
1 parent e0a588a commit 89d6a69

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/callers/ViewCaller.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ public static void setId(View target, String value, Context context) {
1717
}
1818

1919
public static void setLayoutWidth(View target, String value, Context context) {
20-
target.getLayoutParams().width = (int) DimensionUtil.parse(value, context);
21-
target.requestLayout();
20+
if (target.getLayoutParams() != null) {
21+
target.getLayoutParams().width = (int) DimensionUtil.parse(value, context);
22+
target.requestLayout();
23+
}
2224
}
2325

2426
public static void setLayoutHeight(View target, String value, Context context) {
25-
target.getLayoutParams().height = (int) DimensionUtil.parse(value, context);
26-
target.requestLayout();
27+
if (target.getLayoutParams() != null) {
28+
target.getLayoutParams().height = (int) DimensionUtil.parse(value, context);
29+
target.requestLayout();
30+
}
2731
}
2832

2933
public static void setBackground(View target, String value, Context context) {

layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/tools/XMLParserUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ object XmlParserUtils {
5656
attributeMap: MutableMap<View, AttributeMap>,
5757
marker: String
5858
): View = View(context).also {
59+
it.layoutParams = ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
5960
val attrs = AttributeMap().apply { putValue(marker, "true") }
6061
attributeMap[it] = attrs
6162
}

layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/tools/XmlLayoutParser.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@ class XmlLayoutParser(
227227
throw result
228228
} else {
229229
view = result as? View
230-
view?.let { listViews.add(it) }
230+
view?.let {
231+
it.layoutParams = ViewGroup.LayoutParams(
232+
ViewGroup.LayoutParams.WRAP_CONTENT,
233+
ViewGroup.LayoutParams.WRAP_CONTENT,
234+
)
235+
listViews.add(it)
236+
}
231237
}
232238
}
233239
}

0 commit comments

Comments
 (0)