Merge "Fix bug #8052320 RelativeLayout is not having the correct width when in RTL mode - part 2"
This commit is contained in:
committed by
Android (Google) Code Review
commit
7384db20b8
@@ -444,21 +444,14 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
// We need to know our size for doing the correct computation of positioning in RTL mode
|
// We need to know our size for doing the correct computation of positioning in RTL mode
|
||||||
if (isLayoutRtl() && (myWidth == -1 || isWrapContentWidth)) {
|
if (isLayoutRtl() && (myWidth == -1 || isWrapContentWidth)) {
|
||||||
int w = getPaddingStart() + getPaddingEnd();
|
int w = getPaddingStart() + getPaddingEnd();
|
||||||
final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
View child = views[i];
|
View child = views[i];
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
LayoutParams params = (LayoutParams) child.getLayoutParams();
|
LayoutParams params = (LayoutParams) child.getLayoutParams();
|
||||||
// Would be similar to a call to measureChildHorizontal(child, params, -1, myHeight)
|
int[] rules = params.getRules(View.LAYOUT_DIRECTION_LTR);
|
||||||
// but we cannot change for now the behavior of measureChildHorizontal() for
|
|
||||||
// taking care or a "-1" for "mywidth" so use here our own version of that code.
|
applyHorizontalSizeRules(params, myWidth, rules);
|
||||||
int childHeightMeasureSpec;
|
measureChildHorizontal(child, params, -1, myHeight);
|
||||||
if (params.width == LayoutParams.MATCH_PARENT) {
|
|
||||||
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(myHeight, MeasureSpec.EXACTLY);
|
|
||||||
} else {
|
|
||||||
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(myHeight, MeasureSpec.AT_MOST);
|
|
||||||
}
|
|
||||||
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
|
|
||||||
|
|
||||||
w += child.getMeasuredWidth();
|
w += child.getMeasuredWidth();
|
||||||
w += params.leftMargin + params.rightMargin;
|
w += params.leftMargin + params.rightMargin;
|
||||||
@@ -476,13 +469,16 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int layoutDirection = getLayoutDirection();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
View child = views[i];
|
View child = views[i];
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
LayoutParams params = (LayoutParams) child.getLayoutParams();
|
LayoutParams params = (LayoutParams) child.getLayoutParams();
|
||||||
|
int[] rules = params.getRules(layoutDirection);
|
||||||
|
|
||||||
applyHorizontalSizeRules(params, myWidth);
|
applyHorizontalSizeRules(params, myWidth, rules);
|
||||||
measureChildHorizontal(child, params, myWidth, myHeight);
|
measureChildHorizontal(child, params, myWidth, myHeight);
|
||||||
|
|
||||||
if (positionChildHorizontal(child, params, myWidth, isWrapContentWidth)) {
|
if (positionChildHorizontal(child, params, myWidth, isWrapContentWidth)) {
|
||||||
offsetHorizontalAxis = true;
|
offsetHorizontalAxis = true;
|
||||||
}
|
}
|
||||||
@@ -543,8 +539,6 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int layoutDirection = getLayoutDirection();
|
|
||||||
|
|
||||||
if (isWrapContentWidth) {
|
if (isWrapContentWidth) {
|
||||||
// Width already has left padding in it since it was calculated by looking at
|
// Width already has left padding in it since it was calculated by looking at
|
||||||
// the right of each child view
|
// the right of each child view
|
||||||
@@ -862,9 +856,7 @@ public class RelativeLayout extends ViewGroup {
|
|||||||
return rules[ALIGN_PARENT_BOTTOM] != 0;
|
return rules[ALIGN_PARENT_BOTTOM] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyHorizontalSizeRules(LayoutParams childParams, int myWidth) {
|
private void applyHorizontalSizeRules(LayoutParams childParams, int myWidth, int[] rules) {
|
||||||
final int layoutDirection = getLayoutDirection();
|
|
||||||
int[] rules = childParams.getRules(layoutDirection);
|
|
||||||
RelativeLayout.LayoutParams anchorParams;
|
RelativeLayout.LayoutParams anchorParams;
|
||||||
|
|
||||||
// -1 indicated a "soft requirement" in that direction. For example:
|
// -1 indicated a "soft requirement" in that direction. For example:
|
||||||
|
|||||||
Reference in New Issue
Block a user