在CSS中,divs
可以使用float:left
将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;
}
}
放在一行中。
如何实现Xamarin.Forms?
到目前为止我的代码:
wav file
但我需要将红色和绿色布局放在同一行。
答案 0 :(得分:1)
您需要设置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;
}
}