am 1c8107dd: am 5c380efa: Merge "Always distribute excess space in LinearLayout measurement" into mnc-dev
* commit '1c8107dd89c8424c8fad9e341dc43be04e1a62ae': Always distribute excess space in LinearLayout measurement
This commit is contained in:
@@ -686,6 +686,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
int weightedMaxWidth = 0;
|
int weightedMaxWidth = 0;
|
||||||
boolean allFillParent = true;
|
boolean allFillParent = true;
|
||||||
float totalWeight = 0;
|
float totalWeight = 0;
|
||||||
|
int usedExcessSpace = 0;
|
||||||
|
|
||||||
final int count = getVirtualChildCount();
|
final int count = getVirtualChildCount();
|
||||||
|
|
||||||
@@ -730,14 +731,12 @@ public class LinearLayout extends ViewGroup {
|
|||||||
mTotalLength = Math.max(totalLength, totalLength + lp.topMargin + lp.bottomMargin);
|
mTotalLength = Math.max(totalLength, totalLength + lp.topMargin + lp.bottomMargin);
|
||||||
skippedMeasure = true;
|
skippedMeasure = true;
|
||||||
} else {
|
} else {
|
||||||
int oldHeight = Integer.MIN_VALUE;
|
final boolean fillExcessSpace = lp.height == 0 && lp.weight > 0;
|
||||||
|
if (fillExcessSpace) {
|
||||||
if (lp.height == 0 && lp.weight > 0) {
|
|
||||||
// heightMode is either UNSPECIFIED or AT_MOST, and this
|
// heightMode is either UNSPECIFIED or AT_MOST, and this
|
||||||
// child wanted to stretch to fill available space.
|
// child wanted to stretch to fill available space.
|
||||||
// Translate that to WRAP_CONTENT so that it does not end up
|
// Translate that to WRAP_CONTENT so that it does not end up
|
||||||
// with a height of 0
|
// with a height of 0.
|
||||||
oldHeight = 0;
|
|
||||||
lp.height = LayoutParams.WRAP_CONTENT;
|
lp.height = LayoutParams.WRAP_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,11 +748,12 @@ public class LinearLayout extends ViewGroup {
|
|||||||
child, i, widthMeasureSpec, 0, heightMeasureSpec,
|
child, i, widthMeasureSpec, 0, heightMeasureSpec,
|
||||||
totalWeight == 0 ? mTotalLength : 0);
|
totalWeight == 0 ? mTotalLength : 0);
|
||||||
|
|
||||||
if (oldHeight != Integer.MIN_VALUE) {
|
final int childHeight = child.getMeasuredHeight();
|
||||||
lp.height = oldHeight;
|
if (fillExcessSpace) {
|
||||||
|
usedExcessSpace += childHeight;
|
||||||
|
lp.height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int childHeight = child.getMeasuredHeight();
|
|
||||||
final int totalLength = mTotalLength;
|
final int totalLength = mTotalLength;
|
||||||
mTotalLength = Math.max(totalLength, totalLength + childHeight + lp.topMargin +
|
mTotalLength = Math.max(totalLength, totalLength + childHeight + lp.topMargin +
|
||||||
lp.bottomMargin + getNextLocationOffset(child));
|
lp.bottomMargin + getNextLocationOffset(child));
|
||||||
@@ -857,7 +857,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
// Either expand children with weight to take up available space or
|
// Either expand children with weight to take up available space or
|
||||||
// shrink them if they extend beyond our current bounds. If we skipped
|
// shrink them if they extend beyond our current bounds. If we skipped
|
||||||
// measurement on any children, we need to measure them now.
|
// measurement on any children, we need to measure them now.
|
||||||
int delta = heightSize - mTotalLength;
|
final int delta = heightSize - mTotalLength + usedExcessSpace;
|
||||||
if (skippedMeasure || delta != 0 && totalWeight > 0.0f) {
|
if (skippedMeasure || delta != 0 && totalWeight > 0.0f) {
|
||||||
float weightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
|
float weightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
|
||||||
|
|
||||||
@@ -874,34 +874,14 @@ public class LinearLayout extends ViewGroup {
|
|||||||
|
|
||||||
float childExtra = lp.weight;
|
float childExtra = lp.weight;
|
||||||
if (childExtra > 0) {
|
if (childExtra > 0) {
|
||||||
// Child said it could absorb extra space -- give him his share
|
// Distribute excess space to child.
|
||||||
int share = (int) (childExtra * delta / weightSum);
|
final int childHeight = Math.max(0, (int) (childExtra * delta / weightSum));
|
||||||
weightSum -= childExtra;
|
final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight,
|
||||||
delta -= share;
|
MeasureSpec.EXACTLY);
|
||||||
|
|
||||||
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
|
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
|
||||||
mPaddingLeft + mPaddingRight +
|
mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin,
|
||||||
lp.leftMargin + lp.rightMargin, lp.width);
|
lp.width);
|
||||||
|
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
||||||
// TODO: Use a field like lp.isMeasured to figure out if this
|
|
||||||
// child has been previously measured
|
|
||||||
if ((lp.height != 0) || (heightMode != MeasureSpec.EXACTLY)) {
|
|
||||||
// child was measured once already above...
|
|
||||||
// base new measurement on stored values
|
|
||||||
int childHeight = child.getMeasuredHeight() + share;
|
|
||||||
if (childHeight < 0) {
|
|
||||||
childHeight = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
child.measure(childWidthMeasureSpec,
|
|
||||||
MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY));
|
|
||||||
} else {
|
|
||||||
// child was skipped in the loop above.
|
|
||||||
// Measure for this first time here
|
|
||||||
child.measure(childWidthMeasureSpec,
|
|
||||||
MeasureSpec.makeMeasureSpec(share > 0 ? share : 0,
|
|
||||||
MeasureSpec.EXACTLY));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Child may now not fit in vertical dimension.
|
// Child may now not fit in vertical dimension.
|
||||||
childState = combineMeasuredStates(childState, child.getMeasuredState()
|
childState = combineMeasuredStates(childState, child.getMeasuredState()
|
||||||
@@ -1017,6 +997,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
int weightedMaxHeight = 0;
|
int weightedMaxHeight = 0;
|
||||||
boolean allFillParent = true;
|
boolean allFillParent = true;
|
||||||
float totalWeight = 0;
|
float totalWeight = 0;
|
||||||
|
int usedExcessSpace = 0;
|
||||||
|
|
||||||
final int count = getVirtualChildCount();
|
final int count = getVirtualChildCount();
|
||||||
|
|
||||||
@@ -1094,14 +1075,12 @@ public class LinearLayout extends ViewGroup {
|
|||||||
skippedMeasure = true;
|
skippedMeasure = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int oldWidth = Integer.MIN_VALUE;
|
final boolean fillExcessSpace = lp.width == 0 && lp.weight > 0;
|
||||||
|
if (fillExcessSpace) {
|
||||||
if (lp.width == 0 && lp.weight > 0) {
|
|
||||||
// widthMode is either UNSPECIFIED or AT_MOST, and this
|
// widthMode is either UNSPECIFIED or AT_MOST, and this
|
||||||
// child
|
// child wanted to stretch to fill available space.
|
||||||
// wanted to stretch to fill available space. Translate that to
|
// Translate that to WRAP_CONTENT so that it does not end up
|
||||||
// WRAP_CONTENT so that it does not end up with a width of 0
|
// with a width of 0.
|
||||||
oldWidth = 0;
|
|
||||||
lp.width = LayoutParams.WRAP_CONTENT;
|
lp.width = LayoutParams.WRAP_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1113,11 +1092,12 @@ public class LinearLayout extends ViewGroup {
|
|||||||
totalWeight == 0 ? mTotalLength : 0,
|
totalWeight == 0 ? mTotalLength : 0,
|
||||||
heightMeasureSpec, 0);
|
heightMeasureSpec, 0);
|
||||||
|
|
||||||
if (oldWidth != Integer.MIN_VALUE) {
|
final int childWidth = child.getMeasuredWidth();
|
||||||
lp.width = oldWidth;
|
if (fillExcessSpace) {
|
||||||
|
usedExcessSpace += childWidth;
|
||||||
|
lp.width = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int childWidth = child.getMeasuredWidth();
|
|
||||||
if (isExactly) {
|
if (isExactly) {
|
||||||
mTotalLength += childWidth + lp.leftMargin + lp.rightMargin +
|
mTotalLength += childWidth + lp.leftMargin + lp.rightMargin +
|
||||||
getNextLocationOffset(child);
|
getNextLocationOffset(child);
|
||||||
@@ -1242,7 +1222,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
// Either expand children with weight to take up available space or
|
// Either expand children with weight to take up available space or
|
||||||
// shrink them if they extend beyond our current bounds. If we skipped
|
// shrink them if they extend beyond our current bounds. If we skipped
|
||||||
// measurement on any children, we need to measure them now.
|
// measurement on any children, we need to measure them now.
|
||||||
int delta = widthSize - mTotalLength;
|
final int delta = widthSize - mTotalLength + usedExcessSpace;
|
||||||
if (skippedMeasure || delta != 0 && totalWeight > 0.0f) {
|
if (skippedMeasure || delta != 0 && totalWeight > 0.0f) {
|
||||||
float weightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
|
float weightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
|
||||||
|
|
||||||
@@ -1265,34 +1245,13 @@ public class LinearLayout extends ViewGroup {
|
|||||||
float childExtra = lp.weight;
|
float childExtra = lp.weight;
|
||||||
if (childExtra > 0) {
|
if (childExtra > 0) {
|
||||||
// Child said it could absorb extra space -- give him his share
|
// Child said it could absorb extra space -- give him his share
|
||||||
int share = (int) (childExtra * delta / weightSum);
|
final int childWidth = Math.max(0, (int) (childExtra * delta / weightSum));
|
||||||
weightSum -= childExtra;
|
final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth,
|
||||||
delta -= share;
|
MeasureSpec.EXACTLY);
|
||||||
|
final int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
|
||||||
final int childHeightMeasureSpec = getChildMeasureSpec(
|
|
||||||
heightMeasureSpec,
|
|
||||||
mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin,
|
mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin,
|
||||||
lp.height);
|
lp.height);
|
||||||
|
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
||||||
// TODO: Use a field like lp.isMeasured to figure out if this
|
|
||||||
// child has been previously measured
|
|
||||||
if ((lp.width != 0) || (widthMode != MeasureSpec.EXACTLY)) {
|
|
||||||
// child was measured once already above ... base new measurement
|
|
||||||
// on stored values
|
|
||||||
int childWidth = child.getMeasuredWidth() + share;
|
|
||||||
if (childWidth < 0) {
|
|
||||||
childWidth = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
child.measure(
|
|
||||||
MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY),
|
|
||||||
childHeightMeasureSpec);
|
|
||||||
} else {
|
|
||||||
// child was skipped in the loop above. Measure for this first time here
|
|
||||||
child.measure(MeasureSpec.makeMeasureSpec(
|
|
||||||
share > 0 ? share : 0, MeasureSpec.EXACTLY),
|
|
||||||
childHeightMeasureSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Child may now not fit in horizontal dimension.
|
// Child may now not fit in horizontal dimension.
|
||||||
childState = combineMeasuredStates(childState,
|
childState = combineMeasuredStates(childState,
|
||||||
|
|||||||
Reference in New Issue
Block a user