Xamarin在景观上形成堆栈布局填充屏幕

Eri*_*mpo 3 xaml xamarin.forms

当设备处于“横向”模式时,如何将所有屏幕宽度都覆盖在堆栈布局中? 在横向模式下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>
Run Code Online (Sandbox Code Playgroud)

我希望stacklayout在横向上采用屏幕宽度;但只有肖像才能工作。

hva*_*an3 5

当控件是一个直接的儿童AbsoluteLayout设置HorizontalOptions,并VerticalOptions没有任何影响。所有的大小必须来自设置AbsoluteLayout.LayoutBoundsAbsoluteLayout.LayoutFlags。因此,尝试将您的StackLayout更改为此:

<AbsoluteLayout BackgroundColor="Silver"
                HorizontalOptions="FillAndExpand">
  <StackLayout Orientation="Vertical" 
               BackgroundColor="Maroon"
               AbsoluteLayout.LayoutBounds="0,0,1,1"
               AbsoluteLayout.LayoutFlags="All">
    ...
Run Code Online (Sandbox Code Playgroud)

然后,您可能还需要将其设置ListView.HorizontalOptions为,FillAndExpand但请先尝试不这样做。