【问题标题】:How can I create right-aligned items in the ui with Xamarin.Forms?如何使用 Xamarin.Forms 在 ui 中创建右对齐项?
【发布时间】:2014-10-06 00:07:05
【问题描述】:

我尝试使用 StackLayout 和 Grid 创建此页面,但无法将 rightы 控件与右侧对齐。也许我应该使用RelativeLayout?但我不知道如何将控件对齐到右侧

这是我的页面: http://s9.postimg.org/z5ilck6hb/template.png

UPD。 我通过将 StackLayout 和 Horizo​​ntalOptions = LayoutOptions.EndAndExpand 放到每个网格单元(在右列中)来解决了这个问题

【问题讨论】:

    标签: windows-phone-8 xamarin.ios xamarin xamarin.android xamarin.forms


    【解决方案1】:

    如果您想将控件向右对齐,请尝试使用

    HorizontalOptions="EndAndExpand"
    

    使用网格控件,您可以更好地控制对齐方式,因为您可以创建多列(宽度不同)。

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition  Height="40" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="80" />
        </Grid.ColumnDefinitions>
    

    您可以在Learning Xamarin我的系列中找到更多信息

    谢谢。

    -杰西

    【讨论】:

    • 谢谢,杰西,但我想将第一列左对齐,第二列右对齐。你能给我举个例子吗?
    • 不适用于按钮。 EndAndExpand 的工作原理与 Horizo​​ntalOptions="End" 将 Button 缩小到 Text 的大小完全相同。
    猜你喜欢
    • 2016-10-24
    • 2018-12-29
    • 2011-07-07
    • 2018-02-06
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    相关资源
    最近更新 更多