网格不扩展到填充屏幕

时间:2015-07-22 13:25:11

标签: android xamarin android-gridview xamarin.forms

我有以下网格,它被加载到StackLayout中:

            Grid grid = new Grid {
            VerticalOptions = LayoutOptions.FillAndExpand,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            RowDefinitions = 
            {
                new RowDefinition { Height = new GridLength(40, GridUnitType.Auto) },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = GridLength.Auto },
                new RowDefinition { Height = new GridLength(40, GridUnitType.Auto) },
            },
            ColumnDefinitions = 
            {
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Auto) },
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Auto) },
            }
        };

        grid.Children.Add (btnMenu, 0, 1, 0, 1);
        grid.Children.Add (lblProfile, 1, 5, 0, 1);
        grid.Children.Add (btnEdit, 4, 5, 0, 1);
        grid.Children.Add (lblFirstName, 1, 2, 1, 2);
        grid.Children.Add (lblFirstNameValue, 2, 3, 1, 2);

        Content = new StackLayout { 
            HorizontalOptions = LayoutOptions.StartAndExpand,
            Children = { 
                grid
            }
        };

我已经改变了网格的宽度值和宽度类型,但我不能让它填满整个屏幕,除非我使用固定值,这在我的手机上看起来很好,但在其他一切上真的很糟糕

2 个答案:

答案 0 :(得分:7)

尝试将VerticalOptions = LayoutOptions.FillAndExpand添加到父StackLayout

答案 1 :(得分:0)

对于我来说,我必须将VerticalOptions = FillAndExpand添加到父StackLayout并将祖父母Frame设置为Padding = 0