【问题标题】:Fill all the screen with StackLayout用 StackLayout 填满整个屏幕
【发布时间】:2014-08-12 23:08:49
【问题描述】:

我有一个这样编码的 StackLayout:

StackLayout mainStackLayOut = new StackLayout{
    BackgroundColor = Color.Blue,
    //VerticalOptions = LayoutOptions.FillAndExpand,
    //WidthRequest = width,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Orientation = StackOrientation.Vertical
};

但我希望 StackLayout 填充所有屏幕宽度和高度,我还添加了这样的树形按钮:

StackLayout buttonsStackLayOut = new StackLayout
{
    BackgroundColor = Color.White,
    //VerticalOptions = LayoutOptions.Fill,
    HorizontalOptions = LayoutOptions.Fill,
    Orientation = StackOrientation.Horizontal,
    Spacing = 0
};
mainStackLayOut.Children.Add(buttonsStackLayOut);


Image doctorImage = new Image
{
    WidthRequest = width / 3,
    HeightRequest = 50,
    BackgroundColor = Color.Gray,
    Source = ImageSource.FromFile ("about.png")
};
buttonsStackLayOut.Children.Add(doctorImage);

我怎样才能填满所有的屏幕尺寸?

【问题讨论】:

  • 有什么问题?左右两边的黑线?
  • 是的,这正是问题所在
  • 您是否尝试过明确设置 Padding="0"

标签: xamarin xamarin.forms


【解决方案1】:

以最简单的形式,我设法达到了您的要求。

我将屏幕内容设置为主堆栈布局。

        var mainStackLayout = new StackLayout { BackgroundColor = Color.Blue};
        var buttonsStackLayout = new StackLayout { BackgroundColor = Color.White, Orientation = StackOrientation.Horizontal , Spacing = 0 };

        Image about = new Image { HeightRequest = 50, Source = ImageSource.FromFile("about.jpg") };
        Image twitter = new Image { HeightRequest = 50, Source = ImageSource.FromFile("twitter.jpg") };
        Image refresh = new Image { HeightRequest = 50, Source = ImageSource.FromFile("refresh.jpg") };

        buttonsStackLayout.Children.Add(about);
        buttonsStackLayout.Children.Add(twitter);
        buttonsStackLayout.Children.Add(refresh);

        mainStackLayout.Children.Add(buttonsStackLayout);
        this.Content = mainStackLayout; 

【讨论】:

    猜你喜欢
    • 2015-07-31
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多