【问题标题】:How do I center multiline text in a label如何在标签中居中多行文本
【发布时间】:2020-02-12 12:38:34
【问题描述】:

有没有人想出如何使用LineBreakMode=WordWrap 将 Xamarin 表单标签中的文本居中(或证明或以任何方式水平效果)?不使用 WebView(或类似的)?

在这段代码 sn-p 中,所有HorizontalOptions 条目都被愉快地忽略了:

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

看起来像this

【问题讨论】:

标签: xamarin.forms


【解决方案1】:

在这种情况下,您应该使用 Horizo​​ntalTextAlignment="Center"。

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        HorizontalTextAlignment="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

【讨论】:

  • 整洁。我想这是有道理的,因为HorizontalOptions 仅与父级中Label 的位置有关,对吧?谢谢!
【解决方案2】:

在您的代码中添加这一行

Horizo​​ntalTextAlignment="居中"

<StackLayout>
    <Label
        Margin="75,0,75,0"
        FontAttributes="Italic"
        FontSize="Large"
        HorizontalOptions="Center"
        HorizontalTextAlignment="Center"
        LineBreakMode="WordWrap"
        Text="Live life as though nobody is watching, and express yourself as though everyone Is listening."
        VerticalOptions="CenterAndExpand" />
</StackLayout>

【讨论】:

    猜你喜欢
    • 2017-11-27
    • 2022-11-15
    • 2019-02-14
    • 2011-07-15
    • 1970-01-01
    • 2018-02-10
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多