diff --git a/tns-core-modules/ui/action-bar/action-bar-common.ts b/tns-core-modules/ui/action-bar/action-bar-common.ts index 5e13d91c7..b89220006 100644 --- a/tns-core-modules/ui/action-bar/action-bar-common.ts +++ b/tns-core-modules/ui/action-bar/action-bar-common.ts @@ -61,10 +61,18 @@ export class ActionBarBase extends View implements ActionBarDefinition { this._titleView = value; - if (this._titleView) { - this._titleView.style[horizontalAlignmentProperty.cssName] = "center"; - this._titleView.style[verticalAlignmentProperty.cssName] = "middle"; - this._addView(this._titleView); + if (value) { + // Addview will reset CSS properties so we first add it then set aligments with lowest priority. + this._addView(value); + const style = value.style; + + if (!horizontalAlignmentProperty.isSet(style)) { + style[horizontalAlignmentProperty.cssName] = "center"; + } + + if (!verticalAlignmentProperty.isSet(style)) { + style[verticalAlignmentProperty.cssName] = "middle"; + } } this.update(); diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 0397c1ee0..449f866b9 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -370,15 +370,53 @@ export class View extends ViewCommon { get [horizontalAlignmentProperty.native](): HorizontalAlignment { return org.nativescript.widgets.ViewHelper.getHorizontalAlignment(this.nativeView); } - set [horizontalAlignmentProperty.native](value: HorizontalAlignment) { - org.nativescript.widgets.ViewHelper.setHorizontalAlignment(this.nativeView, value); + set [horizontalAlignmentProperty.native](value: HorizontalAlignment)  { + const  nativeView = this.nativeView; + const  lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams(); + // Set only if params gravity exists. + if (lp.gravity !== undefined) { + switch (value) { + case "left": + lp.gravity = android.view.Gravity.LEFT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK); + break; + case "center": + lp.gravity = android.view.Gravity.CENTER_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK); + break; + case "right": + lp.gravity = android.view.Gravity.RIGHT | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK); + break; + case "stretch": + lp.gravity = android.view.Gravity.FILL_HORIZONTAL | (lp.gravity & android.view.Gravity.VERTICAL_GRAVITY_MASK); + break; + } + nativeView.setLayoutParams(lp); + } } get [verticalAlignmentProperty.native](): VerticalAlignment { return org.nativescript.widgets.ViewHelper.getVerticalAlignment(this.nativeView); } set [verticalAlignmentProperty.native](value: VerticalAlignment) { - org.nativescript.widgets.ViewHelper.setVerticalAlignment(this.nativeView, value); + const  nativeView = this.nativeView; + const  lp: any = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams(); + // Set only if params gravity exists. + if (lp.gravity !== undefined) { + switch (value) { + case "top": + lp.gravity = android.view.Gravity.TOP | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK); + break; + case "middle": + lp.gravity = android.view.Gravity.CENTER_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK); + break; + case "bottom": + lp.gravity = android.view.Gravity.BOTTOM | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK); + break; + case "stretch": + lp.gravity = android.view.Gravity.FILL_VERTICAL | (lp.gravity & android.view.Gravity.HORIZONTAL_GRAVITY_MASK); + break; + } + nativeView.setLayoutParams(lp); + } } get [rotateProperty.native](): number {