From 2bd961ae38ebd0acb7d33b32144a3c8a0949c023 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Tue, 27 Aug 2013 19:46:43 -0700 Subject: [PATCH] Fix bug #10514694 Specifying android:gravity="center_vertical|left" results in negative vertical positioning of child - related to "wrap_content" - self bounds should include childs horizontal / vertical margin too - so make height / width computation follow similar pattern as top / bottom computation Passing CTS tests: RelativeLayoutTest / RelativeLayout_LayoutParamsTest Change-Id: Id019c2536e89d2d8a4991aaabf6de60aae2e263b --- core/java/android/widget/RelativeLayout.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java index f73e2c470880d..b9b6b08f957ee 100644 --- a/core/java/android/widget/RelativeLayout.java +++ b/core/java/android/widget/RelativeLayout.java @@ -462,6 +462,7 @@ public class RelativeLayout extends ViewGroup { views = mSortedVerticalChildren; count = views.length; + final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; for (int i = 0; i < count; i++) { View child = views[i]; @@ -476,14 +477,26 @@ public class RelativeLayout extends ViewGroup { if (isWrapContentWidth) { if (isLayoutRtl()) { - width = Math.max(width, myWidth - params.mLeft); + if (targetSdkVersion < Build.VERSION_CODES.KEY_LIME_PIE) { + width = Math.max(width, myWidth - params.mLeft); + } else { + width = Math.max(width, myWidth - params.mLeft - params.leftMargin); + } } else { - width = Math.max(width, params.mRight); + if (targetSdkVersion < Build.VERSION_CODES.KEY_LIME_PIE) { + width = Math.max(width, params.mRight); + } else { + width = Math.max(width, params.mRight + params.rightMargin); + } } } if (isWrapContentHeight) { - height = Math.max(height, params.mBottom); + if (targetSdkVersion < Build.VERSION_CODES.KEY_LIME_PIE) { + height = Math.max(height, params.mBottom); + } else { + height = Math.max(height, params.mBottom + params.bottomMargin); + } } if (child != ignore || verticalGravity) {