如何阻止此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>
答案 0 :(得分:0)
使用“自动”代替“ *”
<RowDefinition Height="Auto"/>
答案 1 :(得分:0)
这似乎是一个错误,其中网格高度被视为图像正以其全部高度显示。
<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>
答案 2 :(得分:0)
Grid
中有一个spacing属性。
Grid
具有控制行和列之间的间距的属性。以下属性可用于自定义Grid
:
6
。6
。您可以设置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>
关于图像,Aspect
属性决定使用Fill
或AspectFill
缩放图像以适合显示区域的方式。(默认为{ {1}})