2016-08-02 154 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