【问题标题】:How to achieve android constraint layout in xamarin forms如何在xamarin表单中实现android约束布局
【发布时间】:2018-10-15 16:48:09
【问题描述】:

我正在 Xamarin 表单中寻找与 Android 的约束布局等效的内容。有没有?如何在 XAML 中实现这一点?我环顾四周,没有发现任何有用的东西。

非常感谢您的任何建议。

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    一般来说,对于我的基本页面布局,我使用网格(但有很多方法可以处理页面布局......) 在这个网格中,您可以放置​​您的 UI 元素。但有趣的是,您可以为网格的每一行和每一列设置宽度 x 高度。

    然后,您还可以为每个 UI 元素设置 margin 属性。

    我不熟悉 Android 设计,但在 Xamarin Forms 中你可以有类似的东西:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.5*" />
            <RowDefinition Height="0.5*" />
        </Grid.RowDefinitions>
    
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.25*" />
            <ColumnDefinition Width="0.75*" />
        </Grid.ColumnDefinitions>
    
        <Label Text="Top Left" Grid.Row="0" Grid.Column="0" Margin="5,10,5,10" />
        <Label Text="Top Right" Grid.Row="0" Grid.Column="1" />
        <Label Text="Bottom Left" Grid.Row="1" Grid.Column="0" />
        <Label Text="Bottom Right" Grid.Row="1" Grid.Column="1" />
    
    </Grid>
    

    此示例生成一个包含 4 个部分(2 行,2 列)的布局。行将具有相同的高度并填满屏幕。第二列将比第一列大 3 倍,并且都将填满屏幕。

    Margin="5,10,5,10" 确保标签前始终存在 5 个“像素”的空白空间,标签顶部存在 10 个“像素”。 .

    有几个控件可以管理布局,例如StackLayoutListview(用于管理项目)。如果您有更具体的示例要实施,请不要犹豫,完成您的问题。

    我建议您查看此文档,您会找到所需的一切! Xamarin Forms layout documentation

    【讨论】:

    • 感谢您的回答,但答案并未回答我的问题。我已经有了具有类似布局的 Grid,但我想实现与 Android 上的约束布局相同的行为。我想实现这种行为。
    猜你喜欢
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多