一行中有两个布局

时间:2015-09-07 10:27:09

标签: c# alignment xamarin.forms

在CSS中,divs可以使用float:leftpublic 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

但我需要将红色和绿色布局放在同一行。

1 个答案:

答案 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;
    }
}