From 3253cd4a22a480eea210c9a76efdceecc5819b8f Mon Sep 17 00:00:00 2001 From: Alexander Djenkov Date: Wed, 11 Jul 2018 11:31:19 +0300 Subject: [PATCH] fix(layout-params): respect width/height properties with percent values (#127) --- .../java/org/nativescript/widgets/CommonLayoutParams.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java b/android/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java index 7c3b6c95f..9398b27ca 100644 --- a/android/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java +++ b/android/widgets/src/main/java/org/nativescript/widgets/CommonLayoutParams.java @@ -118,7 +118,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; // If we have explicit height and gravity is FILL we need to be centered otherwise our explicit height won't be taken into account. - if (lp.height >= 0 && verticalGravity == Gravity.FILL_VERTICAL) { + if ((lp.height >= 0 || lp.heightPercent >= 0) && verticalGravity == Gravity.FILL_VERTICAL) { verticalGravity = Gravity.CENTER_VERTICAL; } @@ -145,7 +145,7 @@ public class CommonLayoutParams extends FrameLayout.LayoutParams { int horizontalGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK; // If we have explicit width and gravity is FILL we need to be centered otherwise our explicit width won't be taken into account. - if (lp.width >= 0 && horizontalGravity == Gravity.FILL_HORIZONTAL) { + if ((lp.width >= 0 || lp.widthPercent >= 0) && horizontalGravity == Gravity.FILL_HORIZONTAL) { horizontalGravity = Gravity.CENTER_HORIZONTAL; }