【发布时间】:2019-11-14 23:11:54
【问题描述】:
在我的 Xamarin Forms 应用程序中,我需要在另一个 flex 布局中拥有一个 flex 布局。这是因为:
- 我需要在我的应用程序中有两列 - 一列占据屏幕的 80%,另一列占据屏幕的 20%。我使用一个带有两个孩子的 FlexLayout,为此设置了 FlexLayout.Basis 属性。
- 在其中一列中,我需要显示一系列视图,以便它们环绕以填充可用空间。我使用设置为 Wrap 的 FlexLayout 来实现这一点。
在此布局下方,我需要显示一些其他控件。 我的问题是包含包装控件的 FlexLayout 没有准确调整其高度,并且“底部”控件侵占了包装布局。这是问题的一个示例(在 Android 中):
Label11 已被按钮遮挡。红色边框是 Android UI Automator Viewer 中 FlexLayout 的边框。高度似乎没有根据已添加的控件进行调整。 如果我删除了“右按钮”列,因此不需要它的弹性基础属性,它的大小会准确。我认为包含包装控件的 FlexLayout 没有考虑到它位于已设置为 80% 宽度的列中的事实 - 它似乎以它的高度为基础,就好像它占据了屏幕的整个宽度一样。有谁知道解决这个问题的方法? 这是重现问题的 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:FlexLayoutProb"
x:Class="FlexLayoutProb.MainPage">
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
AutomationId="stackLayoutTop">
<FlexLayout
AutomationId="FlexLayoutTop"
HorizontalOptions="FillAndExpand"
VerticalOptions="Start"
>
<StackLayout AutomationId="stackLayoutLeft" FlexLayout.Basis="80%" HorizontalOptions="FillAndExpand" >
<FlexLayout
AutomationId="FlexLayoutCtrls"
HorizontalOptions="FillAndExpand"
VerticalOptions="Start"
Wrap="Wrap" BackgroundColor="LightGreen"
>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label1"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label2"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label3"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label4"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label5"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label6"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label7"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label8"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label9"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label10"></Label>
<Label HeightRequest="50" WidthRequest="100" Margin="5" BackgroundColor="LightCyan" Text="Label11"></Label>
</FlexLayout>
</StackLayout>
<StackLayout AutomationId="stackLayoutRight" FlexLayout.Basis="20%" HorizontalOptions="FillAndExpand">
<Button Text="Right Button" HorizontalOptions="FillAndExpand"></Button>
</StackLayout>
</FlexLayout>
<Button Text="Bottom Button"></Button>
</StackLayout>
</ContentPage>
【问题讨论】:
-
因为标签的宽度超过了屏幕的大小,可以试试Grid with '*'。
-
@LucasZhang-MSFT 是的,我确实在下面看到了 - 很抱歉没有尽快回复您。
标签: xaml layout xamarin.forms