XamarinForm 中的网格是否可以实现这种布局?

问题描述 投票:0回答:1

我想创建一个具有以下结构的网格布局:2 行和 1 列。我想在网格的顶部放置一个黄色的控件,它不受网格的约束。

黄色控件表示顶层状态。

xamarin grid
1个回答
0
投票

可以把网格放到AbsoluteLayout中,然后用另一个控件覆盖网格。如:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App23.Page2">
    <ContentPage.Content>
        <StackLayout>
          <AbsoluteLayout HeightRequest="600">
            <Grid AbsoluteLayout.LayoutBounds="0,0,600,400" RowSpacing="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="3*"/>
                    <RowDefinition Height="7*"/>
                </Grid.RowDefinitions>
                <StackLayout HorizontalOptions="Fill" BackgroundColor="Green" Grid.Row="0"/>
                <StackLayout HorizontalOptions="Fill" BackgroundColor="Blue" Grid.Row="1"/>
            </Grid>
            <StackLayout  BackgroundColor="Red"
                         AbsoluteLayout.LayoutBounds="0,0,140,140"/>
          </AbsoluteLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

结果图像:

© www.soinside.com 2019 - 2024. All rights reserved.