C# 一行两个布局
在CSS中,可以使用C# 一行两个布局,c#,alignment,xamarin.forms,C#,Alignment,Xamarin.forms,在CSS中,可以使用float:left将两个div放在一行中 Xamarin.Forms如何实现这一点 到目前为止,我掌握的代码是: public class App : Application { public App () { StackLayout sl2 = new StackLayout (); sl2.WidthRequest = 400; sl2.HeightRequest = 400; sl2.Ba
float:left
将两个div
放在一行中
Xamarin.Forms如何实现这一点
到目前为止,我掌握的代码是:
public class App : Application
{
public App ()
{
StackLayout sl2 = new StackLayout ();
sl2.WidthRequest = 400;
sl2.HeightRequest = 400;
sl2.BackgroundColor = Color.Red;
sl2.HorizontalOptions = LayoutOptions.Start;
StackLayout sl3 = new StackLayout ();
sl3.WidthRequest = 400;
sl3.HeightRequest = 400;
sl3.BackgroundColor = Color.Green;
sl3.HorizontalOptions = LayoutOptions.Start;
StackLayout sl = new StackLayout ();
sl.Children.Add(sl2);
sl.Children.Add(sl3);
ContentPage contentPage = new ContentPage ();
contentPage.Content = sl;
MainPage = contentPage;
}
}
但是我需要把红色和绿色的布局放在同一行
您需要设置
StackLayout.Orientation
属性:
public class App : Application
{
public App ()
{
StackLayout sl2 = new StackLayout ();
sl2.WidthRequest = 400;
sl2.HeightRequest = 400;
sl2.BackgroundColor = Color.Red;
sl2.HorizontalOptions = LayoutOptions.Start;
StackLayout sl3 = new StackLayout ();
sl3.WidthRequest = 400;
sl3.HeightRequest = 400;
sl3.BackgroundColor = Color.Green;
sl3.HorizontalOptions = LayoutOptions.Start;
StackLayout sl = new StackLayout ();
sl.Orientation = StackOrientation.Horizontal
sl.Children.Add(sl2);
sl.Children.Add(sl3);
ContentPage contentPage = new ContentPage ();
contentPage.Content = sl;
MainPage = contentPage;
}
}