diff options
author | Romain Guy <romainguy@google.com> | 2010-02-25 11:02:24 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-02-25 11:02:24 -0800 |
commit | d0c6182cb925ad59b24810280b357cacc959f111 (patch) | |
tree | 72a714a2b8ba05b926059da343d9d7698ed593c9 /core/java | |
parent | ee74858f1f68a915ab42b89a258ff1e7eff47b06 (diff) | |
parent | c352090c49b50a70aaddeb428bd5e27f7419884f (diff) | |
download | frameworks_base-d0c6182cb925ad59b24810280b357cacc959f111.zip frameworks_base-d0c6182cb925ad59b24810280b357cacc959f111.tar.gz frameworks_base-d0c6182cb925ad59b24810280b357cacc959f111.tar.bz2 |
Merge "Correctly handle negative margins in horizontal linear layouts."
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/widget/LinearLayout.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index 4bd3a82..bd07e1f 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -632,6 +632,8 @@ public class LinearLayout extends ViewGroup { final boolean baselineAligned = mBaselineAligned; final boolean useLargestChild = mUseLargestChild; + + final boolean isExactly = widthMode == MeasureSpec.EXACTLY; int largestChildWidth = Integer.MIN_VALUE; @@ -658,7 +660,13 @@ public class LinearLayout extends ViewGroup { // Optimization: don't bother measuring children who are going to use // leftover space. These views will get measured again down below if // there is any leftover space. - mTotalLength += lp.leftMargin + lp.rightMargin; + if (isExactly) { + mTotalLength += lp.leftMargin + lp.rightMargin; + } else { + final int totalLength = mTotalLength; + mTotalLength = Math.max(totalLength, totalLength + + lp.leftMargin + lp.rightMargin); + } // Baseline alignment requires to measure widgets to obtain the // baseline offset (in particular for TextViews). The following @@ -694,8 +702,14 @@ public class LinearLayout extends ViewGroup { } final int childWidth = child.getMeasuredWidth(); - mTotalLength += childWidth + lp.leftMargin + lp.rightMargin + - getNextLocationOffset(child); + if (isExactly) { + mTotalLength += childWidth + lp.leftMargin + lp.rightMargin + + getNextLocationOffset(child); + } else { + final int totalLength = mTotalLength; + mTotalLength = Math.max(totalLength, totalLength + childWidth + lp.leftMargin + + lp.rightMargin + getNextLocationOffset(child)); + } if (useLargestChild) { largestChildWidth = Math.max(childWidth, largestChildWidth); @@ -780,8 +794,14 @@ public class LinearLayout extends ViewGroup { final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); - mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin + - getNextLocationOffset(child); + if (isExactly) { + mTotalLength += largestChildWidth + lp.leftMargin + lp.rightMargin + + getNextLocationOffset(child); + } else { + final int totalLength = mTotalLength; + mTotalLength = Math.max(totalLength, totalLength + largestChildWidth + + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child)); + } } } @@ -851,8 +871,14 @@ public class LinearLayout extends ViewGroup { } } - mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin + - getNextLocationOffset(child); + if (isExactly) { + mTotalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin + + getNextLocationOffset(child); + } else { + final int totalLength = mTotalLength; + mTotalLength = Math.max(totalLength, totalLength + child.getMeasuredWidth() + + lp.leftMargin + lp.rightMargin + getNextLocationOffset(child)); + } boolean matchHeightLocally = heightMode != MeasureSpec.EXACTLY && lp.height == LayoutParams.MATCH_PARENT; |