diff options
| author | Fabrice Di Meglio <fdimeglio@google.com> | 2012-11-29 14:33:10 -0800 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-11-29 14:33:10 -0800 |
| commit | 0feedf9982e60915f11f52dc0504d827800d6601 (patch) | |
| tree | 6f434f1df81ebd26b52a7141863a7e97abcc99a4 /core/java/android/widget/RelativeLayout.java | |
| parent | b34aedcf6899ba509fb3a5ad0bcfb8bdf9af7b6d (diff) | |
| parent | cd91470aad09ee7b501ed1d585b9a23f66a718b6 (diff) | |
am cd91470a: am 146b1290: am cdc6d5cf: Merge "Fix bug #7617883 RelativeLayout is not having the correct width when in RTL mode" into jb-mr1.1-dev
* commit 'cd91470aad09ee7b501ed1d585b9a23f66a718b6':
Fix bug #7617883 RelativeLayout is not having the correct width when in RTL mode
Diffstat (limited to 'core/java/android/widget/RelativeLayout.java')
| -rw-r--r-- | core/java/android/widget/RelativeLayout.java | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index 83b6a005810f..a5eb28143fb5 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -413,6 +413,32 @@ public class RelativeLayout extends ViewGroup { View[] views = mSortedHorizontalChildren; int count = views.length; + + // We need to know our size for doing the correct computation of positioning in RTL mode + if (isLayoutRtl() && (myWidth == -1 || isWrapContentWidth)) { + myWidth = getPaddingStart() + getPaddingEnd(); + final int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + for (int i = 0; i < count; i++) { + View child = views[i]; + if (child.getVisibility() != GONE) { + LayoutParams params = (LayoutParams) child.getLayoutParams(); + // Would be similar to a call to measureChildHorizontal(child, params, -1, myHeight) + // 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. + int childHeightMeasureSpec; + if (params.width == LayoutParams.MATCH_PARENT) { + childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(myHeight, MeasureSpec.EXACTLY); + } else { + childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(myHeight, MeasureSpec.AT_MOST); + } + child.measure(childWidthMeasureSpec, childHeightMeasureSpec); + + myWidth += child.getMeasuredWidth(); + myWidth += params.leftMargin + params.rightMargin; + } + } + } + for (int i = 0; i < count; i++) { View child = views[i]; if (child.getVisibility() != GONE) { @@ -933,7 +959,7 @@ public class RelativeLayout extends ViewGroup { // Find the first non-GONE view up the chain while (v.getVisibility() == View.GONE) { - rules = ((LayoutParams) v.getLayoutParams()).getRules(); + rules = ((LayoutParams) v.getLayoutParams()).getRules(v.getLayoutDirection()); node = mGraph.mKeyNodes.get((rules[relation])); if (node == null) return null; v = node.view; @@ -984,7 +1010,7 @@ public class RelativeLayout extends ViewGroup { protected void onLayout(boolean changed, int l, int t, int r, int b) { // The layout has actually already been performed and the positions // cached. Apply the cached values to the children. - int count = getChildCount(); + final int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); |
