[英]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
:
6
.6
。6
.6
。 You can set RowSpacing
or ColumnSpacing
to check whether can solve it.您可以设置
RowSpacing
或ColumnSpacing
来检查是否可以解决它。
<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
)关于Image ,
Aspect
属性确定如何缩放图像以适应显示区域,使用Fill
或AspectFill
。(默认为AspectFit
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.