Skip to content

Instantly share code, notes, and snippets.

@kumarandena
Last active May 9, 2019 06:41
Show Gist options
  • Save kumarandena/c2dd9423e5d94061599c4892e1744798 to your computer and use it in GitHub Desktop.
Save kumarandena/c2dd9423e5d94061599c4892e1744798 to your computer and use it in GitHub Desktop.
Vertically Center Label Text in NativeScript Android

There are some differences how iOS and Android work with layouts with no predefined sizes which is causing this different output for your code. In your case your Label is wrapped in the default StackLayout with no dimensions and this is one of the reason not to be able to position your label at the vertical center. Another thing is the percentage value of your label set to 100%.

What I can suggest is to use different layouts for cases when you need to control both horizonal and vertical aligment.

e.g.

<GridLayout rows="*" columns="*" style.backgroundColor="gray" >
    <Label row="0" text="vertically centered" style.verticalAlignment="center" style.textAlignment="center" textWrap="true">       </Label>
</GridLayout>

With the above snippet, we are creating a GridLayout which will take all the available space for rows and columns (using *) and for that space will position your label vertically aligned to the center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment