gpt4 book ai didi

xaml - Xamarin Forms stacklayout 在横向上填充屏幕

转载 作者:行者123 更新时间:2023-12-01 06:02:33 25 4
gpt4 key购买 nike

当设备处于横向时,如何让 stacklayout 占用所有屏幕宽度?
in Landscape mode stacklayout does not fill parent

这是我的 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 在横向上采用屏幕宽度;但只有在肖像上是工作。

最佳答案

当控件是 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但先试试没有那个。

关于xaml - Xamarin Forms stacklayout 在横向上填充屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38726836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com