簡體   English   中英

如何在 StackLayout 中水平居中 FlexLayout?

[英]How do I horizontally center a FlexLayout inside a StackLayout?

我在FlexLayout中有一個StackLayout

<StackLayout HorizontalOptions="Center" Padding="0,100">
    <Label
        Text="Franklin"
        HorizontalTextAlignment="Center"
        FontSize="Large" />
    <Label Text="Mostly Cloudy" HorizontalTextAlignment="Center" />
    <Label
        Text="55°"
        HorizontalTextAlignment="Center"
        FontSize="Header" />

    <!-- PLEASE CENTER ME -->
    <FlexLayout>
        <Label Text="H:55°" Margin="0,0,10,0" />
        <Label Text="L:37°" />
    </FlexLayout>

</StackLayout>

StackLayout 中的 FlexLayout

如何在FlexLayout中將StackLayout

我建議在水平方向使用StackLayout StackLayout 提供了將元素放置在頁面中的更自然的流程。

<!-- This part is now centered -->
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
    <Label Text="H:55°" Padding="5,0" />
    <Label Text="L:37°" Padding="5,0" />
</StackLayout>

FlexLayout包裝在AbsoluteLayout中:

<!-- This part is now centered -->
<AbsoluteLayout HorizontalOptions="CenterAndExpand">
    <FlexLayout>
        <Label Text="H:55°" Padding="5,0" />
        <Label Text="L:37°" Padding="5,0" />
    </FlexLayout>
</AbsoluteLayout>

FlexLayout 以 StackLayout 為中心

請注意,我將第一個 label 上的邊距拆分為兩個標簽之間的填充,以便它們在FlexLayout內居中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM