diff options
author | Alan Viverette <alanv@google.com> | 2015-03-09 18:01:19 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2015-03-09 18:01:19 -0700 |
commit | 0e14a8576845fa336836519f0fe356d17682238e (patch) | |
tree | ebcffa35ac3bddca1cecbf29949830e7b61ca376 | |
parent | 3c36b8e9569292b7da9a916b148a21dd6c273dc9 (diff) | |
download | frameworks_base-0e14a8576845fa336836519f0fe356d17682238e.zip frameworks_base-0e14a8576845fa336836519f0fe356d17682238e.tar.gz frameworks_base-0e14a8576845fa336836519f0fe356d17682238e.tar.bz2 |
Revert RelativeLayout's baseline view to API 22 and below behavior
The previous behavior used the top-start-most view, rather than the view
with the bottom-most baseline. Which doesn't really make sense, but
that's what it did.
Bug: 19653790
Change-Id: Ia23476f1d2de5313fd82aac037e90d45b0af8972
-rw-r--r-- | core/java/android/widget/RelativeLayout.java | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index a224f5e..d12739f 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -515,6 +515,23 @@ public class RelativeLayout extends ViewGroup { } } + // Use the top-start-most laid out view as the baseline. RTL offsets are + // applied later, so we can use the left-most edge as the starting edge. + View baselineView = null; + LayoutParams baselineParams = null; + for (int i = 0; i < count; i++) { + final View child = getChildAt(i); + if (child.getVisibility() != GONE) { + final LayoutParams childParams = (LayoutParams) child.getLayoutParams(); + if (baselineView == null || baselineParams == null + || compareLayoutPosition(childParams, baselineParams) < 0) { + baselineView = child; + baselineParams = childParams; + } + } + } + mBaselineView = baselineView; + if (isWrapContentWidth) { // Width already has left padding in it since it was calculated by looking at // the right of each child view @@ -616,25 +633,24 @@ public class RelativeLayout extends ViewGroup { } } - // Use the bottom-most laid out view as the baseline. - View baselineView = null; - int baseline = 0; - for (int i = 0; i < count; i++) { - final View child = getChildAt(i); - if (child.getVisibility() != GONE) { - final int childBaseline = child.getBaseline(); - if (childBaseline >= baseline) { - baselineView = child; - baseline = childBaseline; - } - } - } - mBaselineView = baselineView; - setMeasuredDimension(width, height); } /** + * @return a negative number if the top of {@code p1} is above the top of + * {@code p2} or if they have identical top values and the left of + * {@code p1} is to the left of {@code p2}, or a positive number + * otherwise + */ + private int compareLayoutPosition(LayoutParams p1, LayoutParams p2) { + final int topDiff = p1.mTop - p2.mTop; + if (topDiff != 0) { + return topDiff; + } + return p1.mLeft - p2.mLeft; + } + + /** * Measure a child. The child should have left, top, right and bottom information * stored in its LayoutParams. If any of these values is VALUE_NOT_SET it means * that the view can extend up to the corresponding edge. |