From c29f031598811486d83f418fd08fbfe1fc41788a Mon Sep 17 00:00:00 2001 From: Philip Milne Date: Wed, 22 Feb 2012 16:34:51 -0800 Subject: Fix for bug 6050753. The method: TypedArray: getLayoutDimension(int, String) throws an undocumented exception when either the width and/or height attributes are undefined. See the bug report above for reasons why this was deemed unhelpful both in the tools area and to developers in general. Fix by: 1. Documenting the conditions under which the method raises an exception. 2. Deprecating the method, advising callers to supply a default instead. Additionally, redefine the: ViewGroup: setBaseAttributes(TypedArray, int, int); methods to provide the appropriate defaults in ViewGroup subclasses as advised above. For the platform layouts the default value is WRAP_CONTENT (and is defined in the ViewGroup.LayoutParams class). The special cases are accomodated in LayoutParams subclasses in the following cases: Subclass width height FrameLayout.LayoutParams: MATCH_PARENT, MATCH_PARENT TableLayout.LayoutParams: MATCH_PARENT, WRAP_CONTENT TableRow.LayoutParams: MATCH_PARENT, WRAP_CONTENT Change-Id: I335a3bd8e2d7f7866692898ed73492635a5b61ea --- core/java/android/view/ViewGroup.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core/java/android/view/ViewGroup.java') diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index c68d77d6d3ac..b97dca3c6bff 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -5089,15 +5089,19 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } /** - * Extracts the layout parameters from the supplied attributes. + * Extracts the width and height layout parameters + * from the supplied TypedArray, a, and assigns them + * to the appropriate fields. If, a, does not contain an + * entry for either attribute, the value, {@link ViewGroup.LayoutParams#WRAP_CONTENT}, + * is used as a default. * * @param a the style attributes to extract the parameters from * @param widthAttr the identifier of the width attribute * @param heightAttr the identifier of the height attribute */ protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) { - width = a.getLayoutDimension(widthAttr, "layout_width"); - height = a.getLayoutDimension(heightAttr, "layout_height"); + width = a.getLayoutDimension(widthAttr, WRAP_CONTENT); + height = a.getLayoutDimension(heightAttr, WRAP_CONTENT); } /** -- cgit v1.2.3