Nativescript: StackLayout + Label with horizontal-align renders differently on iOS and Android

Created on 13 May 2016  路  9Comments  路  Source: NativeScript/NativeScript

Tested on iOS 9.3 and Android API 23
When we have StackLayout with Label as a child and we set horizontal-align:center the result is that the Label position renders differently on the different platforms.
Code to reproduce the issue:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
  <StackLayout>
      <Label text="Label" fontSize="24"/> 
      <Button text="TAP" tap="" />
  </StackLayout>
</Page>
StackLayout {
    horizontal-align: center;
    width: 100%;
    height: 100%;
}

result
screen shot 2016-05-13 at 3 46 07 pm

Most helpful comment

In android what is happening is that, you have set the width and height of stacklayout as 100% it covers the whole screen and the layout will be center horizontally but the views inside it wont be horizontally center to get the text center you need to do this

<Label text="Label" fontSize="24" class="textcenter"/>

.textcenter{
  text-align: center;
}

and remove

width: 100%;
height: 100%;

All 9 comments

In android what is happening is that, you have set the width and height of stacklayout as 100% it covers the whole screen and the layout will be center horizontally but the views inside it wont be horizontally center to get the text center you need to do this

<Label text="Label" fontSize="24" class="textcenter"/>

.textcenter{
  text-align: center;
}

and remove

width: 100%;
height: 100%;

screenshot_2016-05-21-01-54-52

So I think ios is not rendering it correctly.

It feels that ios is wrapping the views.

width: 100%;
height: 100%;

is not applied to the stacklayout in ios.

Can you post the screenshot of ios version in which the stacklayout has some background other than white to check whether stacklayout is filling the entire screen or not.

Everything is working exactly the same on both platforms.

I removed all the CSS, colored all the elements and added small margins so you can better see what goes where. Here is what the following XML will produce on both platforms:

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" style.backgroundColor="green">
  <StackLayout style.backgroundColor="yellow" margin="5">
      <Label text="Label" fontSize="24" style.backgroundColor="red" margin="5" style.textAlignment="center"/> 
      <Button text="TAP" style.backgroundColor="blue" margin="5"/>
  </StackLayout>
</Page>

screen shot 2016-06-29 at 2 35 08 pm

Everything is working correctly and in identical manner on both platforms so I will close this issue, since there is no issue at all.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Leo-lay picture Leo-lay  路  3Comments

kn9ts picture kn9ts  路  3Comments

minjunlan picture minjunlan  路  3Comments

NordlingDev picture NordlingDev  路  3Comments

OscarLopezArnaiz picture OscarLopezArnaiz  路  3Comments