【发布时间】:2019-09-11 07:37:41
【问题描述】:
使用StartAndExpand 或EndAndExpand 似乎并没有真正扩展StackLayout 中的元素。即使有更多可用空间,如蓝色区域所示。只有FillAndExpand 有效。
代码如下:
<?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:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:local="clr-namespace:App6"
x:Class="App6.MainPage"
ios:Page.UseSafeArea="True">
<StackLayout BackgroundColor="Blue"
HeightRequest="100"
Orientation="Horizontal"
Spacing="0"
VerticalOptions="Start">
<Label BackgroundColor="Red"
HorizontalOptions="Start"
Text="Hi" />
<StackLayout BackgroundColor="Salmon"
HorizontalOptions="EndAndExpand"
Orientation="Vertical">
<BoxView BackgroundColor="Red"
HeightRequest="30"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="30" />
</StackLayout>
</StackLayout>
</ContentPage>
这是我得到的:
当对子 StackLayout 使用 FillAndExpand 时,最重要的结果是不展开的 EndAndExpand,最后是同样不展开的 StartAndExpand。
如果父元素有更多空间,难道不应该扩展元素吗?如果是,那为什么StartAndExpand 和EndAndExpand 不起作用?
注意:仅在 Android 上使用 Xamarin.Forms 版本 3.4.0.1008975 进行测试。
【问题讨论】:
-
如果父视图大于其所有子视图的组合大小,即额外空间可用,则空间在具有该后缀的子视图之间按比例分配。那些孩子会“占据”他们的空间,但不一定会“填满”它。stackoverflow.com/questions/25338533/…
-
@AndroDevil 哇,这出乎意料。在我在这里发布之前,我实际上阅读了这个问题,但这对我来说没有意义。因为如果空间给了一个元素,并且元素默认布局选项是填充,它应该填充那个可用空间。但是不,StackLayout 更像是 FlexLayout 之间的空间。它只是在元素之间分配空间而不给它们。太棒了。
标签: android xamarin.forms