diff options
| author | 2015-07-30 17:18:44 +0000 | |
|---|---|---|
| committer | 2015-07-30 17:18:44 +0000 | |
| commit | 82c14e6865d58b719e583e1ee4c7a405a41d57ea (patch) | |
| tree | 9c56147fd5d6f02c32d24864f8d88b7090625335 | |
| parent | 06e544f0bef0973167f768a8dd9402c85d456612 (diff) | |
| parent | 92360585abfb96736f5b55b5410425eb4ad7669c (diff) | |
am 92360585: am 559daf7a: Merge "Include non-zero dimension views in excess space calculation" into mnc-dev
* commit '92360585abfb96736f5b55b5410425eb4ad7669c':
Include non-zero dimension views in excess space calculation
| -rw-r--r-- | core/java/android/widget/LinearLayout.java | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index 4b405014fed6..47e894aaa619 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -722,8 +722,10 @@ public class LinearLayout extends ViewGroup { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); totalWeight += lp.weight; - - if (heightMode == MeasureSpec.EXACTLY && lp.height == 0 && lp.weight > 0) { + + final boolean fillExcessSpace = lp.weight > 0; + final boolean hasZeroHeight = lp.height == 0; + if (heightMode == MeasureSpec.EXACTLY && fillExcessSpace && hasZeroHeight) { // 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. @@ -731,12 +733,12 @@ public class LinearLayout extends ViewGroup { mTotalLength = Math.max(totalLength, totalLength + lp.topMargin + lp.bottomMargin); skippedMeasure = true; } else { - final boolean fillExcessSpace = lp.height == 0 && lp.weight > 0; - if (fillExcessSpace) { - // heightMode is either UNSPECIFIED or AT_MOST, and this - // child wanted to stretch to fill available space. - // Translate that to WRAP_CONTENT so that it does not end up - // with a height of 0. + if (fillExcessSpace && hasZeroHeight) { + // The LinearLayout's heightMode is either UNSPECIFIED or + // AT_MOST, and this child wanted to stretch to fill + // available space. Translate the explicit height of 0 to + // WRAP_CONTENT so that we can measure the view's ideal + // height. lp.height = LayoutParams.WRAP_CONTENT; } @@ -751,7 +753,11 @@ public class LinearLayout extends ViewGroup { final int childHeight = child.getMeasuredHeight(); if (fillExcessSpace) { usedExcessSpace += childHeight; - lp.height = 0; + + // Restore original layout height. + if (hasZeroHeight) { + lp.height = 0; + } } final int totalLength = mTotalLength; @@ -1047,8 +1053,10 @@ public class LinearLayout extends ViewGroup { child.getLayoutParams(); totalWeight += lp.weight; - - if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && lp.weight > 0) { + + final boolean fillExcessSpace = lp.weight > 0; + final boolean hasZeroWidth = lp.width == 0; + if (widthMode == MeasureSpec.EXACTLY && fillExcessSpace && hasZeroWidth) { // 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. @@ -1075,12 +1083,12 @@ public class LinearLayout extends ViewGroup { skippedMeasure = true; } } else { - final boolean fillExcessSpace = lp.width == 0 && lp.weight > 0; - if (fillExcessSpace) { - // widthMode is either UNSPECIFIED or AT_MOST, and this - // child wanted to stretch to fill available space. - // Translate that to WRAP_CONTENT so that it does not end up - // with a width of 0. + if (fillExcessSpace && hasZeroWidth) { + // The LinearLayout's widthMode is either UNSPECIFIED or + // AT_MOST, and this child wanted to stretch to fill + // available space. Translate the explicit height of 0 to + // WRAP_CONTENT so that we can measure the view's ideal + // width. lp.width = LayoutParams.WRAP_CONTENT; } @@ -1095,7 +1103,11 @@ public class LinearLayout extends ViewGroup { final int childWidth = child.getMeasuredWidth(); if (fillExcessSpace) { usedExcessSpace += childWidth; - lp.width = 0; + + // Restore the original layout width. + if (hasZeroWidth) { + lp.width = 0; + } } if (isExactly) { |