am dbb79ae9: am 4cf97c91: am 7bfe7b5b: am 5cca30a4: Merge "Revert two changes to LinearLayout measurement" into mnc-dev
* commit 'dbb79ae9dc457bcb97794f718c6d3aa7fc4a19ca': Revert two changes to LinearLayout measurement
This commit is contained in:
@@ -686,7 +686,6 @@ 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();
|
||||||
|
|
||||||
@@ -723,9 +722,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
|
|
||||||
totalWeight += lp.weight;
|
totalWeight += lp.weight;
|
||||||
|
|
||||||
final boolean fillExcessSpace = lp.weight > 0;
|
if (heightMode == MeasureSpec.EXACTLY && lp.height == 0 && 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
|
// Optimization: don't bother measuring children who are going to use
|
||||||
// leftover space. These views will get measured again down below if
|
// leftover space. These views will get measured again down below if
|
||||||
// there is any leftover space.
|
// there is any leftover space.
|
||||||
@@ -733,12 +730,14 @@ 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 {
|
||||||
if (fillExcessSpace && hasZeroHeight) {
|
int oldHeight = Integer.MIN_VALUE;
|
||||||
// The LinearLayout's heightMode is either UNSPECIFIED or
|
|
||||||
// AT_MOST, and this child wanted to stretch to fill
|
if (lp.height == 0 && lp.weight > 0) {
|
||||||
// available space. Translate the explicit height of 0 to
|
// heightMode is either UNSPECIFIED or AT_MOST, and this
|
||||||
// WRAP_CONTENT so that we can measure the view's ideal
|
// child wanted to stretch to fill available space.
|
||||||
// height.
|
// Translate that to WRAP_CONTENT so that it does not end up
|
||||||
|
// with a height of 0
|
||||||
|
oldHeight = 0;
|
||||||
lp.height = LayoutParams.WRAP_CONTENT;
|
lp.height = LayoutParams.WRAP_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,16 +749,11 @@ public class LinearLayout extends ViewGroup {
|
|||||||
child, i, widthMeasureSpec, 0, heightMeasureSpec,
|
child, i, widthMeasureSpec, 0, heightMeasureSpec,
|
||||||
totalWeight == 0 ? mTotalLength : 0);
|
totalWeight == 0 ? mTotalLength : 0);
|
||||||
|
|
||||||
final int childHeight = child.getMeasuredHeight();
|
if (oldHeight != Integer.MIN_VALUE) {
|
||||||
if (fillExcessSpace) {
|
lp.height = oldHeight;
|
||||||
usedExcessSpace += childHeight;
|
|
||||||
|
|
||||||
// Restore original layout height.
|
|
||||||
if (hasZeroHeight) {
|
|
||||||
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));
|
||||||
@@ -863,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.
|
||||||
final int delta = heightSize - mTotalLength + usedExcessSpace;
|
int delta = heightSize - mTotalLength;
|
||||||
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;
|
||||||
|
|
||||||
@@ -880,14 +874,34 @@ public class LinearLayout extends ViewGroup {
|
|||||||
|
|
||||||
float childExtra = lp.weight;
|
float childExtra = lp.weight;
|
||||||
if (childExtra > 0) {
|
if (childExtra > 0) {
|
||||||
// Distribute excess space to child.
|
// Child said it could absorb extra space -- give him his share
|
||||||
final int childHeight = Math.max(0, (int) (childExtra * delta / weightSum));
|
int share = (int) (childExtra * delta / weightSum);
|
||||||
final int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight,
|
weightSum -= childExtra;
|
||||||
MeasureSpec.EXACTLY);
|
delta -= share;
|
||||||
|
|
||||||
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
|
final int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
|
||||||
mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin,
|
mPaddingLeft + mPaddingRight +
|
||||||
lp.width);
|
lp.leftMargin + lp.rightMargin, 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()
|
||||||
@@ -1003,7 +1017,6 @@ 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();
|
||||||
|
|
||||||
@@ -1054,9 +1067,7 @@ public class LinearLayout extends ViewGroup {
|
|||||||
|
|
||||||
totalWeight += lp.weight;
|
totalWeight += lp.weight;
|
||||||
|
|
||||||
final boolean fillExcessSpace = lp.weight > 0;
|
if (widthMode == MeasureSpec.EXACTLY && lp.width == 0 && 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
|
// Optimization: don't bother measuring children who are going to use
|
||||||
// leftover space. These views will get measured again down below if
|
// leftover space. These views will get measured again down below if
|
||||||
// there is any leftover space.
|
// there is any leftover space.
|
||||||
@@ -1083,12 +1094,14 @@ public class LinearLayout extends ViewGroup {
|
|||||||
skippedMeasure = true;
|
skippedMeasure = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fillExcessSpace && hasZeroWidth) {
|
int oldWidth = Integer.MIN_VALUE;
|
||||||
// The LinearLayout's widthMode is either UNSPECIFIED or
|
|
||||||
// AT_MOST, and this child wanted to stretch to fill
|
if (lp.width == 0 && lp.weight > 0) {
|
||||||
// available space. Translate the explicit height of 0 to
|
// widthMode is either UNSPECIFIED or AT_MOST, and this
|
||||||
// WRAP_CONTENT so that we can measure the view's ideal
|
// child
|
||||||
// width.
|
// wanted to stretch to fill available space. Translate that to
|
||||||
|
// WRAP_CONTENT so that it does not end up with a width of 0
|
||||||
|
oldWidth = 0;
|
||||||
lp.width = LayoutParams.WRAP_CONTENT;
|
lp.width = LayoutParams.WRAP_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1100,16 +1113,11 @@ public class LinearLayout extends ViewGroup {
|
|||||||
totalWeight == 0 ? mTotalLength : 0,
|
totalWeight == 0 ? mTotalLength : 0,
|
||||||
heightMeasureSpec, 0);
|
heightMeasureSpec, 0);
|
||||||
|
|
||||||
final int childWidth = child.getMeasuredWidth();
|
if (oldWidth != Integer.MIN_VALUE) {
|
||||||
if (fillExcessSpace) {
|
lp.width = oldWidth;
|
||||||
usedExcessSpace += childWidth;
|
|
||||||
|
|
||||||
// Restore the original layout width.
|
|
||||||
if (hasZeroWidth) {
|
|
||||||
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);
|
||||||
@@ -1234,7 +1242,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.
|
||||||
final int delta = widthSize - mTotalLength + usedExcessSpace;
|
int delta = widthSize - mTotalLength;
|
||||||
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;
|
||||||
|
|
||||||
@@ -1257,13 +1265,34 @@ 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
|
||||||
final int childWidth = Math.max(0, (int) (childExtra * delta / weightSum));
|
int share = (int) (childExtra * delta / weightSum);
|
||||||
final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth,
|
weightSum -= childExtra;
|
||||||
MeasureSpec.EXACTLY);
|
delta -= share;
|
||||||
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