1

我将 2 个孩子添加到这样的网格中:

    private void pInitStackLayout()
    {
        grid1 = new Grid()
        {
        };

        grid2 = new Grid()
        {
        };

        biggrid = new Grid()
        {
            BackgroundColor = Color.Transparent,
            Margin = new Thickness(0),
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.StartAndExpand,
            Orientation = StackOrientation.Vertical,
        };
        biggrid.Children.Add(grid1,0,0);
        biggrid.Children.Add(grid2,0,1);

        this.Content = biggrid;
    }

ContentPage(这是一个导航页面)的内容是大网格。

我想让 grid1 占据可用高度的 80%,而 grid2 占据 20%(或其余部分)。

我怎么能做到这一点?

4

1 回答 1

2

其实很简单,只需设置biggrid.

// RowDefinitions isolated

RowDefinitions = new RowDefinitionCollection
{
    new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
    new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
}

// RowDefinitions isolated

// Actual code
private void pInitStackLayout()
{
    grid1 = new Grid()
    {
    };

    grid2 = new Grid()
    {
    };

    biggrid = new Grid()
    {
        RowDefinitions = new RowDefinitionCollection
        {
            new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
            new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
        },

        BackgroundColor = Color.Transparent,
        Margin = new Thickness(0),
        HorizontalOptions = LayoutOptions.FillAndExpand,
        VerticalOptions = LayoutOptions.StartAndExpand,
        Orientation = StackOrientation.Vertical,
    };
    biggrid.Children.Add(grid1,0,0);
    biggrid.Children.Add(grid2,0,1);

    this.Content = biggrid;
}
于 2017-11-27T20:34:02.520 回答