2014-06-23 20 views
8

我有一個stacklayout編碼是這樣的:填寫所有的屏幕採用了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); 

enter image description here

我怎麼能填補所有的屏幕尺寸?

+0

什麼問題?左側和右側的黑色線條? –

+0

是的,這就是問題 –

+2

您是否嘗試明確設置Padding =「0」 –

回答

8

以最簡單的形式,我已經設法達到您的要求。

我將屏幕的內容設置爲主堆棧佈局。

 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; 

enter image description here