summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alan Viverette <alanv@google.com> 2016-05-05 02:26:44 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-05-05 02:26:45 +0000
commita11c21b41239c9101a2a1f4e5870b2f819d0e92d (patch)
treee84c6dd616876beef60f4dbf8ace2ccf0eaa5963
parent4e0114742a86ba3c3c9fb9cc536823be44712c05 (diff)
parentcc26636f08da89f9750f550d66aa213f1ae24f7f (diff)
Merge "Always assign leftover pixels to last weighted child" into nyc-dev
-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 f75b74bb9a14..0b73afb657f7 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -708,6 +708,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;
@@ -729,8 +730,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) {
@@ -885,7 +888,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;
@@ -1046,6 +1055,7 @@ public class LinearLayout extends ViewGroup {
final boolean isExactly = widthMode == MeasureSpec.EXACTLY;
+ int lastWeightedChildIndex = -1;
int largestChildWidth = Integer.MIN_VALUE;
int usedExcessSpace = 0;
@@ -1067,8 +1077,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) {
@@ -1267,7 +1279,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;