gpt4 book ai didi

xamarin - 用StackLayout填充所有屏幕

转载 作者:行者123 更新时间:2023-12-04 03:58:02 25 4
gpt4 key购买 nike

我有一个这样的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);

如何填满所有屏幕尺寸?

最佳答案

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

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

        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;

关于xamarin - 用StackLayout填充所有屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24356965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com