summaryrefslogtreecommitdiff
path: root/core/java/android/widget/LinearLayout.java
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2016-05-05 02:34:30 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-05-05 02:34:30 +0000
commit363a5d1f2aa04eadee4e52f09068dc558e2847e3 (patch)
treef4dfead555f3a6dd003367cfd67fe35ef23e06d7 /core/java/android/widget/LinearLayout.java
parent33e5d34b8d03ffae783493a91cbb18e49b7ea0c3 (diff)
parent8902b962250439c5a0f80b3cca4c39bc9ee0fa73 (diff)
Merge "Always assign leftover pixels to last weighted child" into nyc-dev am: a11c21b412 am: 9204810e66
am: 8902b96225 * commit '8902b962250439c5a0f80b3cca4c39bc9ee0fa73': Always assign leftover pixels to last weighted child Change-Id: Ib229a7cc5550942eb094c8d549711129af8594a0
Diffstat (limited to 'core/java/android/widget/LinearLayout.java')
-rw-r--r--core/java/android/widget/LinearLayout.java30
1 files changed, 24 insertions, 6 deletions
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 3ced25359397..d4df3e65437f 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -730,6 +730,7 @@ public class LinearLayout extends ViewGroup {
final int baselineChildIndex = mBaselineAlignedChildIndex;
final boolean useLargestChild = mUseLargestChild;
+ int lastWeightedChildIndex = -1;
int largestChildHeight = Integer.MIN_VALUE;
int consumedExcessSpace = 0;
@@ -754,8 +755,10 @@ public class LinearLayout extends ViewGroup {
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
-
- totalWeight += lp.weight;
+ if (lp.weight > 0) {
+ totalWeight += lp.weight;
+ lastWeightedChildIndex = i;
+ }
final boolean useExcessSpace = lp.height == 0 && lp.weight > 0;
if (heightMode == MeasureSpec.EXACTLY && useExcessSpace) {
@@ -909,7 +912,13 @@ public class LinearLayout extends ViewGroup {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final float childWeight = lp.weight;
if (childWeight > 0) {
- final int share = (int) (childWeight * remainingExcess / remainingWeightSum);
+ final int share;
+ if (i == lastWeightedChildIndex) {
+ share = remainingExcess;
+ } else {
+ share = (int) (childWeight * remainingExcess / remainingWeightSum);
+ }
+
remainingExcess -= share;
remainingWeightSum -= childWeight;
@@ -1070,6 +1079,7 @@ public class LinearLayout extends ViewGroup {
final boolean isExactly = widthMode == MeasureSpec.EXACTLY;
+ int lastWeightedChildIndex = -1;
int largestChildWidth = Integer.MIN_VALUE;
int usedExcessSpace = 0;
@@ -1094,8 +1104,10 @@ public class LinearLayout extends ViewGroup {
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
-
- totalWeight += lp.weight;
+ if (lp.weight > 0) {
+ totalWeight += lp.weight;
+ lastWeightedChildIndex = i;
+ }
final boolean useExcessSpace = lp.width == 0 && lp.weight > 0;
if (widthMode == MeasureSpec.EXACTLY && useExcessSpace) {
@@ -1294,7 +1306,13 @@ public class LinearLayout extends ViewGroup {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final float childWeight = lp.weight;
if (childWeight > 0) {
- final int share = (int) (childWeight * remainingExcess / remainingWeightSum);
+ final int share;
+ if (i == lastWeightedChildIndex) {
+ share = remainingExcess;
+ } else {
+ share = (int) (childWeight * remainingExcess / remainingWeightSum);
+ }
+
remainingExcess -= share;
remainingWeightSum -= childWeight;