Loading core/java/android/widget/LinearLayout.java +89 −20 Original line number Diff line number Diff line Loading @@ -94,6 +94,9 @@ public class LinearLayout extends ViewGroup { @ViewDebug.ExportedProperty private float mWeightSum; @ViewDebug.ExportedProperty private boolean mUseLargestChild; private int[] mMaxAscent; private int[] mMaxDescent; Loading Loading @@ -134,6 +137,9 @@ public class LinearLayout extends ViewGroup { mBaselineAlignedChildIndex = a.getInt(com.android.internal.R.styleable.LinearLayout_baselineAlignedChildIndex, -1); // TODO: Better name, add Java APIs, make it public mUseLargestChild = a.getBoolean(R.styleable.LinearLayout_useLargestChild, false); a.recycle(); } Loading Loading @@ -328,6 +334,9 @@ public class LinearLayout extends ViewGroup { boolean matchWidth = false; final int baselineChildIndex = mBaselineAlignedChildIndex; final boolean useLargestChild = mUseLargestChild; int largestChildHeight = Integer.MIN_VALUE; // See how tall everyone is. Also remember max width. for (int i = 0; i < count; ++i) { Loading Loading @@ -375,8 +384,13 @@ public class LinearLayout extends ViewGroup { lp.height = oldHeight; } mTotalLength += child.getMeasuredHeight() + lp.topMargin + final int childHeight = child.getMeasuredHeight(); mTotalLength += childHeight + lp.topMargin + lp.bottomMargin + getNextLocationOffset(child); if (useLargestChild) { largestChildHeight = Math.max(childHeight, largestChildHeight); } } /** Loading Loading @@ -427,6 +441,29 @@ public class LinearLayout extends ViewGroup { i += getChildrenSkipCount(child, i); } if (useLargestChild) { mTotalLength = 0; for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child == null) { mTotalLength += measureNullChild(i); continue; } if (child.getVisibility() == GONE) { i += getChildrenSkipCount(child, i); continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); mTotalLength += largestChildHeight + lp.topMargin+ lp.bottomMargin + getNextLocationOffset(child); } } // Add in our padding mTotalLength += mPaddingTop + mPaddingBottom; Loading Loading @@ -587,6 +624,9 @@ public class LinearLayout extends ViewGroup { maxDescent[0] = maxDescent[1] = maxDescent[2] = maxDescent[3] = -1; final boolean baselineAligned = mBaselineAligned; final boolean useLargestChild = mUseLargestChild; int largestChildWidth = Integer.MIN_VALUE; // See how wide everyone is. Also remember max height. for (int i = 0; i < count; ++i) { Loading @@ -602,7 +642,8 @@ public class LinearLayout extends ViewGroup { continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); totalWeight += lp.weight; Loading Loading @@ -644,8 +685,13 @@ public class LinearLayout extends ViewGroup { lp.width = oldWidth; } mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); final int childWidth = child.getMeasuredWidth(); mTotalLength += childWidth + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); if (useLargestChild) { largestChildWidth = Math.max(childWidth, largestChildWidth); } } boolean matchHeightLocally = false; Loading Loading @@ -708,6 +754,29 @@ public class LinearLayout extends ViewGroup { maxHeight = Math.max(maxHeight, ascent + descent); } if (useLargestChild) { mTotalLength = 0; for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child == null) { mTotalLength += measureNullChild(i); continue; } if (child.getVisibility() == GONE) { i += getChildrenSkipCount(child, i); continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); } } // Add in our padding mTotalLength += mPaddingLeft + mPaddingRight; Loading Loading @@ -953,7 +1022,7 @@ public class LinearLayout extends ViewGroup { final int paddingLeft = mPaddingLeft; int childTop = mPaddingTop; int childLeft = paddingLeft; int childLeft; // Where right end of child should go final int width = mRight - mLeft; Loading Loading @@ -1038,7 +1107,7 @@ public class LinearLayout extends ViewGroup { void layoutHorizontal() { final int paddingTop = mPaddingTop; int childTop = paddingTop; int childTop; int childLeft = mPaddingLeft; // Where bottom of child should go Loading Loading @@ -1103,7 +1172,7 @@ public class LinearLayout extends ViewGroup { break; case Gravity.CENTER_VERTICAL: // Removed support for baselign alignment when layout_gravity or // Removed support for baseline alignment when layout_gravity or // gravity == center_vertical. See bug #1038483. // Keep the code around if we need to re-enable this feature // if (childBaseline != -1) { Loading core/res/res/layout/alert_dialog.xml +2 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,8 @@ android:orientation="horizontal" android:paddingTop="4dip" android:paddingLeft="2dip" android:paddingRight="2dip" > android:paddingRight="2dip" android:useLargestChild="true"> <LinearLayout android:id="@+id/leftSpacer" android:layout_weight="0.25" android:layout_width="0dip" Loading core/res/res/values/attrs.xml +4 −0 Original line number Diff line number Diff line Loading @@ -1700,6 +1700,10 @@ space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0. --> <attr name="weightSum" format="float" /> <!-- When set to true, all children with a weight will be considered having the minimum size of the largest child. If false, all children are measured normally. --> <attr name="useLargestChild" format="boolean" /> </declare-styleable> <declare-styleable name="ListView"> <!-- Reference to an array resource that will populate the ListView. For static content, Loading Loading
core/java/android/widget/LinearLayout.java +89 −20 Original line number Diff line number Diff line Loading @@ -94,6 +94,9 @@ public class LinearLayout extends ViewGroup { @ViewDebug.ExportedProperty private float mWeightSum; @ViewDebug.ExportedProperty private boolean mUseLargestChild; private int[] mMaxAscent; private int[] mMaxDescent; Loading Loading @@ -134,6 +137,9 @@ public class LinearLayout extends ViewGroup { mBaselineAlignedChildIndex = a.getInt(com.android.internal.R.styleable.LinearLayout_baselineAlignedChildIndex, -1); // TODO: Better name, add Java APIs, make it public mUseLargestChild = a.getBoolean(R.styleable.LinearLayout_useLargestChild, false); a.recycle(); } Loading Loading @@ -328,6 +334,9 @@ public class LinearLayout extends ViewGroup { boolean matchWidth = false; final int baselineChildIndex = mBaselineAlignedChildIndex; final boolean useLargestChild = mUseLargestChild; int largestChildHeight = Integer.MIN_VALUE; // See how tall everyone is. Also remember max width. for (int i = 0; i < count; ++i) { Loading Loading @@ -375,8 +384,13 @@ public class LinearLayout extends ViewGroup { lp.height = oldHeight; } mTotalLength += child.getMeasuredHeight() + lp.topMargin + final int childHeight = child.getMeasuredHeight(); mTotalLength += childHeight + lp.topMargin + lp.bottomMargin + getNextLocationOffset(child); if (useLargestChild) { largestChildHeight = Math.max(childHeight, largestChildHeight); } } /** Loading Loading @@ -427,6 +441,29 @@ public class LinearLayout extends ViewGroup { i += getChildrenSkipCount(child, i); } if (useLargestChild) { mTotalLength = 0; for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child == null) { mTotalLength += measureNullChild(i); continue; } if (child.getVisibility() == GONE) { i += getChildrenSkipCount(child, i); continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); mTotalLength += largestChildHeight + lp.topMargin+ lp.bottomMargin + getNextLocationOffset(child); } } // Add in our padding mTotalLength += mPaddingTop + mPaddingBottom; Loading Loading @@ -587,6 +624,9 @@ public class LinearLayout extends ViewGroup { maxDescent[0] = maxDescent[1] = maxDescent[2] = maxDescent[3] = -1; final boolean baselineAligned = mBaselineAligned; final boolean useLargestChild = mUseLargestChild; int largestChildWidth = Integer.MIN_VALUE; // See how wide everyone is. Also remember max height. for (int i = 0; i < count; ++i) { Loading @@ -602,7 +642,8 @@ public class LinearLayout extends ViewGroup { continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); totalWeight += lp.weight; Loading Loading @@ -644,8 +685,13 @@ public class LinearLayout extends ViewGroup { lp.width = oldWidth; } mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); final int childWidth = child.getMeasuredWidth(); mTotalLength += childWidth + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); if (useLargestChild) { largestChildWidth = Math.max(childWidth, largestChildWidth); } } boolean matchHeightLocally = false; Loading Loading @@ -708,6 +754,29 @@ public class LinearLayout extends ViewGroup { maxHeight = Math.max(maxHeight, ascent + descent); } if (useLargestChild) { mTotalLength = 0; for (int i = 0; i < count; ++i) { final View child = getVirtualChildAt(i); if (child == null) { mTotalLength += measureNullChild(i); continue; } if (child.getVisibility() == GONE) { i += getChildrenSkipCount(child, i); continue; } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child); } } // Add in our padding mTotalLength += mPaddingLeft + mPaddingRight; Loading Loading @@ -953,7 +1022,7 @@ public class LinearLayout extends ViewGroup { final int paddingLeft = mPaddingLeft; int childTop = mPaddingTop; int childLeft = paddingLeft; int childLeft; // Where right end of child should go final int width = mRight - mLeft; Loading Loading @@ -1038,7 +1107,7 @@ public class LinearLayout extends ViewGroup { void layoutHorizontal() { final int paddingTop = mPaddingTop; int childTop = paddingTop; int childTop; int childLeft = mPaddingLeft; // Where bottom of child should go Loading Loading @@ -1103,7 +1172,7 @@ public class LinearLayout extends ViewGroup { break; case Gravity.CENTER_VERTICAL: // Removed support for baselign alignment when layout_gravity or // Removed support for baseline alignment when layout_gravity or // gravity == center_vertical. See bug #1038483. // Keep the code around if we need to re-enable this feature // if (childBaseline != -1) { Loading
core/res/res/layout/alert_dialog.xml +2 −1 Original line number Diff line number Diff line Loading @@ -109,7 +109,8 @@ android:orientation="horizontal" android:paddingTop="4dip" android:paddingLeft="2dip" android:paddingRight="2dip" > android:paddingRight="2dip" android:useLargestChild="true"> <LinearLayout android:id="@+id/leftSpacer" android:layout_weight="0.25" android:layout_width="0dip" Loading
core/res/res/values/attrs.xml +4 −0 Original line number Diff line number Diff line Loading @@ -1700,6 +1700,10 @@ space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0. --> <attr name="weightSum" format="float" /> <!-- When set to true, all children with a weight will be considered having the minimum size of the largest child. If false, all children are measured normally. --> <attr name="useLargestChild" format="boolean" /> </declare-styleable> <declare-styleable name="ListView"> <!-- Reference to an array resource that will populate the ListView. For static content, Loading