包含Xamarin形式的网格的堆栈布局之间的间距

问题描述 投票:0回答:1

我对Xamarin还是比较陌生,我正在尝试实现如下所示的屏幕:

enter image description here

对于我列出的垂直项目,我为每个项目创建了单独的StackLayout(以便将来如果我需要在特定项目中添加某些内容,我可以做到这一点),它们本身就具有Grid进一步具有IconLabel的。像这样的东西(我不能使用XAML,而必须在其中进行编码):

 ysiStackLayout layoutPropertyDashboardIem = new ysiStackLayout()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.Center,
       };

        layoutDashboardItems.Children.Add(layoutPropertyDashboardIem);

        Grid gridProperty = new Grid()
        {
            HorizontalOptions = LayoutOptions.Center,
            RowDefinitions = {
                new RowDefinition { Height = GridLength.Auto }
            },
            ColumnDefinitions =
            {
                new ColumnDefinition {Width = GridLength.Auto}
            },
            ColumnSpacing = 1
        };

        layoutPropertyDashboardIem.Children.Add(gridProperty); 

        ysiIcon iconProperty = new ysiIcon()
        {
            Icon = IconSet.fa_AngleDoubleLeft,
            IconSize = 30
        };

        gridProperty.Children.Add(iconProperty, 0, 0);

        ysiLabel labelProperty = new ysiLabel()
        {
            Text = "Property"
        };

        gridProperty.Children.Add(labelProperty, 1, 0);

`这给了我正确的必要物品;enter image description here

但是令人讨厌的是,我无法给出两个项目之间的间距。我尝试了SpacingPadding之类的属性,但无法找到确切的方法。有人可以请我指导我可以选择的方法吗?确实会有很多帮助!

xaml xamarin xamarin.forms xamarin.android xamarin.ios
1个回答
0
投票

首先,如果可行,我建议先添加子项,然后再将父项添加到根布局。

因此,请创建您的网格,将项目添加到该网格,然后将该网格添加到父级StackLayout

要增加间距,我会尝试Spacing和/或Margin

ysiStackLayout layoutPropertyDashboardIem = new ysiStackLayout() {
    HorizontalOptions = LayoutOptions.FillAndExpand,
    VerticalOptions = LayoutOptions.Center,
    Spacing = 5                                 // Adding Spacing
};

Grid gridProperty = new Grid() {
    HorizontalOptions = LayoutOptions.Center,
    RowDefinitions = { new RowDefinition { Height = GridLength.Auto } },
    ColumnDefinitions = { new ColumnDefinition {Width = GridLength.Auto} },
    ColumnSpacing = 1,
    Margin = new Thickness(5)                   // Adding Margin
};

ysiIcon iconProperty = new ysiIcon() {
    Icon = IconSet.fa_AngleDoubleLeft,
    IconSize = 30
};

gridProperty.Children.Add(iconProperty, 0, 0);

ysiLabel labelProperty = new ysiLabel { Text = "Property" };

gridProperty.Children.Add(labelProperty, 1, 0);

layoutPropertyDashboardIem.Children.Add(gridProperty); // Add children in reverse order up the layout tree

layoutDashboardItems.Children.Add(layoutPropertyDashboardIem); // Add children in reverse order up the layout tree
© www.soinside.com 2019 - 2024. All rights reserved.