【问题标题】:Xamarin: Grid in AbsoluteLayout not fill screenXamarin:AbsoluteLayout中的网格不填满屏幕
【发布时间】:2022-02-18 18:33:17
【问题描述】:

我有一个包含网格的 absolutLayout。如图所示,absoluteLayout 正确地水平填充了屏幕。问题似乎是网格,它没有为屏幕的整个水平长度绘制,留下一个空白部分。如果我尝试将网格移到absoluteLayout之外,网格正确地水平填充屏幕,所以我认为问题与absoluteLayout + grid组合有关。 我对absoluteLayouts知之甚少,不明白如何解决这个问题。

Xaml(为方便起见,我省略了绘制网格中包含的元素的代码):

            <AbsoluteLayout BackgroundColor="Red">
            <Grid x:Name="GridDettaglio" Padding="4,2" ColumnSpacing="1" BackgroundColor="Aqua" HorizontalOptions="Fill" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70"/>    <!--0-->
                    <ColumnDefinition Width="30"/>    <!--1-->
                    <ColumnDefinition Width="70"/>    <!--2-->
                    <ColumnDefinition Width="40"/>    <!--3-->
                    <ColumnDefinition Width="70"/>    <!--4-->
                    <ColumnDefinition Width="30"/>    <!--5-->
                    <ColumnDefinition Width="*"/>     <!--6-->
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/> 
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
              
            </Grid>
        </AbsoluteLayout>

【问题讨论】:

    标签: xaml xamarin layout


    【解决方案1】:

    我不知道你为什么要使用 absolutelayout,但要让它填满屏幕,你通常不需要给它任何东西,但由于它不是自己做的,只需给它下面的标志和边界:

    <Grid AbsoluteLayout.LayoutBounds="0,0,1,1"
                 AbsoluteLayout.LayoutFlags="All" 
    

    如果您有任何疑问,欢迎随时回复。

    【讨论】:

    • 太棒了!可以,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 2020-01-19
    • 2012-11-02
    • 2014-03-15
    • 2019-01-28
    • 2012-04-02
    相关资源
    最近更新 更多