简体   繁体   English

如何删除这个额外的网格空间?

[英]How Can I Remove This Extra Grid Space?

How can I stop this Grid from expanding vertically and adding all this extra space between the rows?如何阻止此 Grid 垂直扩展并在行之间添加所有这些额外空间?

在此处输入图像描述

<ContentPage.Content>
    <StackLayout>

        <Grid>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <Image Source="testsquare" />
            <Image Source="testsquare" Grid.Column="1"/>

            <Image Source="testsquare" Grid.Row="1"/>
            <Image Source="testsquare" Grid.Column="1" Grid.Row="1"/>
        </Grid>
    </StackLayout>

</ContentPage.Content>

This is what it should look like (ignore the background color change)这是它应该看起来的样子(忽略背景颜色的变化) 在此处输入图像描述

Use "Auto" instead of "*"使用“自动”而不是“*”

<RowDefinition Height="Auto"/>

It appears to be a bug, where the grid height is being treated as if the image is being displayed at its full height.这似乎是一个错误,其中网格高度被视为图像以其全高显示。

<Grid BackgroundColor="CornflowerBlue">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

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

    <Image Source="testsquare" />
    <Image Source="testsquare" Grid.Column="1" />

</Grid>

在此处输入图像描述

There is a spacing property in Grid . Grid中有一个间距属性。

Grid has properties to control spacing between rows and columns. Grid具有控制行和列之间间距的属性。 The following properties are available for customizing the Grid :以下属性可用于自定义Grid

  • ColumnSpacing – the amount of space between columns. ColumnSpacing – 列之间的空间量。 The default value of this property is 6 .此属性的默认值为6
  • RowSpacing – the amount of space between rows. RowSpacing – 行之间的空间量。 The default value of this property is 6 .此属性的默认值为6

You can set RowSpacing or ColumnSpacing to check whether can solve it.您可以设置RowSpacingColumnSpacing来检查是否可以解决它。

<StackLayout Padding="5">

    <Grid RowSpacing="5" ColumnSpacing="5">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Image Source="icon.png" BackgroundColor="Accent"/>
        <Image Source="icon.png"
               BackgroundColor="Accent"
               Grid.Column="1" />

        <Image Source="icon.png"
               BackgroundColor="Accent"
               Grid.Row="1" />
        <Image Source="icon.png"
               BackgroundColor="Accent"
               Grid.Column="1"
               Grid.Row="1" />
    </Grid>
</StackLayout>

在此处输入图像描述

About Image , The Aspect property determines how the image will be scaled to fit the display area, with Fill or AspectFill .(Default is AspectFit )关于ImageAspect属性确定如何缩放图像以适应显示区域,使用FillAspectFill 。(默认为AspectFit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM