2014-06-23 10 views
8

ho uno stackLayout codificato come questo:Occupa tutto lo schermo con uno stackLayout

StackLayout mainStackLayOut = new StackLayout{ 
    BackgroundColor = Color.Blue, 
    //VerticalOptions = LayoutOptions.FillAndExpand, 
    //WidthRequest = width, 
    HorizontalOptions = LayoutOptions.FillAndExpand, 
    Orientation = StackOrientation.Vertical 
}; 

Ma voglio che il mio stackLayout per riempire tutta la larghezza dello schermo e l'altezza, anche io ho i pulsanti albero aggiunto in questo modo:

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

Come faccio a riempire tutto lo Screensize?

+0

qual è il problema? le linee nere a sinistra e a destra? –

+0

Sì, esattamente questo è il problema –

+2

hai provato a impostare esplicitamente Padding = "0" –

risposta

8

Nella forma più semplice sono riuscito a ottenere ciò che richiedete.

Ho impostato il contenuto dello schermo sul layout dello stack principale.

 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

Problemi correlati