【问题标题】:How to set FlexLayout height automatically according to its children height如何根据子项高度自动设置 FlexLayout 高度
【发布时间】:2019-03-11 21:17:28
【问题描述】:

我正在尝试创建一个 FlexLayout 而不指定它的高度,因为我假设它会从其子级高度获取它。当我这样做时,FlexLayout 根本不显示。这是一个简单的代码:

<FlexLayout Direction="Column">
    <Button Text="Test Button" />
    <!-- Here I'm trying to create FlexLayout without specifying its height -->
    <FlexLayout JustifyContent="Start" AlignItems="Start" AlignContent="Start" BackgroundColor="Blue" Direction="RowReverse" Wrap="Wrap">
        <Label Text="Test Label" HeightRequest="50" WidthRequest="50"  BackgroundColor="Yellow" />
    </FlexLayout>
</FlexLayout>

我尝试了所有方法,但没有任何效果,除非我为(内部)FlexLayout 指定 HeightRequest 或 FlexLayout.Basis。 任何建议将不胜感激。

【问题讨论】:

  • 你为什么要把 label 标签包裹在另一个 flexlayout 标签里面?
  • @FabriBertani 这只是一个示例。里面会有更多的控制。第一个flexlayout是垂直对齐控件,而第二个是从右到左浮动控件。

标签: xamarin xamarin.forms


【解决方案1】:

如果我将第一个FlexLayout 更改为StackLayout,如下所示,它将起作用。这太奇怪了,因为我认为它应该可以在不将其更改为 StackLayout 的情况下工作:

<StackLayout Orientation="Vertical" Spacing="0">
    <Button Text="Test Button" />
    <FlexLayout JustifyContent="Start" AlignItems="Start" AlignContent="Start" BackgroundColor="Blue" Direction="RowReverse" Wrap="Wrap">
        <Label Text="Test Label" HeightRequest="50" WidthRequest="50"  BackgroundColor="Yellow" />
    </FlexLayout>
</StackLayout>

【讨论】:

    猜你喜欢
    • 2017-12-17
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2019-06-25
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多