Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2bd961ae authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Fix bug #10514694 Specifying android:gravity="center_vertical|left" results in...

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
parent c2b582c0
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -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()) {
                        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 {
                        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) {
                    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) {