2016-08-02 157 views
1

如何設置stacklayout當設備處於橫向時採取所有屏幕寬度? in Landscape mode stacklayout does not fill parentXamarin形式stacklayout橫向填充屏幕

這裏是我的XAML:

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     xmlns:local="clr-namespace:ListView" 
     x:Class="ListView.MainPage"> 
<ContentPage.Content> 
     <AbsoluteLayout BackgroundColor="Silver" HorizontalOptions="FillAndExpand"> 
     <StackLayout Orientation="Vertical" HorizontalOptions="StartAndExpand" BackgroundColor="Maroon" VerticalOptions="StartAndExpand"> 
      <Button Text="Reload data" Clicked="reloadData" x:Name="btnReload"/> 
      <ListView x:Name="listView"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <ViewCell> 
          <StackLayout BackgroundColor="#eee" Orientation="Vertical"> 
           <StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand"> 
            <Image Source="{Binding Imagen}" HeightRequest="100" WidthRequest="120"/> 
            <Label Text="{Binding Titulo}" TextColor="Gray"/> 
            <Label Text="{Binding Fecha}" HorizontalOptions="EndAndExpand"/> 
           </StackLayout> 
          </StackLayout> 
         </ViewCell> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 
     </StackLayout> 
     <ActivityIndicator BackgroundColor="Green" AbsoluteLayout.LayoutBounds=".5,.5,.2,.2" AbsoluteLayout.LayoutFlags="All" Color="Blue" 
          IsRunning="True" IsVisible="False" x:Name="overlay"/> 
    </AbsoluteLayout> 
</ContentPage.Content> 

我想stacklayout採取屏幕寬度的景觀;但只有肖像是工作。

回答

2

當控件是直接子AbsoluteLayout設置HorizontalOptionsVerticalOptions沒有效果。所有尺寸必須來自設置AbsoluteLayout.LayoutBoundsAbsoluteLayout.LayoutFlags。因此,嘗試改變你的StackLayout這樣:

<AbsoluteLayout BackgroundColor="Silver" 
       HorizontalOptions="FillAndExpand"> 
    <StackLayout Orientation="Vertical" 
       BackgroundColor="Maroon" 
       AbsoluteLayout.LayoutBounds="0,0,1,1" 
       AbsoluteLayout.LayoutFlags="All"> 
    ... 

那麼你可能還需要設置你的ListView.HorizontalOptionsFillAndExpand但嘗試沒有,第一。

+0

現在工作:)和真正清楚的答案。非常感謝 –

+0

@EricOcampo完全沒問題。很高興它對你有效。 – hvaughan3