Don't think of it as vertically centring your labels text. Instead put your Label
in a container and centre it relative to the container.
<StackLayout verticalAlignment="center">
<Label text="test" />
</StackLayout>
This will centre align your Label
(vertically) within the StackLayout
. You'll also notice the StackLayout
will now only take up the vertical space required by its children. If you want it to use up more vertical space you just need to give it a height.
The following creates a three row GridLayout
with each row occupying 33.3...% of the screen with their labels centred within them.
<Page xmlns="http://www.nativescript.org/tns.xsd">
<GridLayout rows="*, *, *">
<StackLayout row="0" class="red stack">
<Label text="red" class="label"/>
</StackLayout>
<StackLayout row="1" class="green stack">
<Label text="green" class="label"/>
</StackLayout>
<StackLayout row="2" class="blue stack">
<Label text="blue" class="label"/>
</StackLayout>
</GridLayout>
</Page>
.stack {
height: 100%;
vertical-align: center;
}
.label { text-align: center; }
.red { backgroundColor: red; }
.green { backgroundColor: green; }
.blue { backgroundColor: blue; }
Here's a Playground of the above if you'd like to see it working on your device. Try commenting out the height
property in home-page.css
(line 13).