c# - Xamarin Forms:图像网格在元素行之间有太多空间
问题描述
我有一个包含 2 列的网格,用于托管图像。
<ScrollView VerticalOptions="Start">
<Grid
x:Name="gridLayout"
RowSpacing="5"
VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</ScrollView>
图像是以编程方式添加的,因为我不知道执行之前的数量。像这样声明图像
Image image = new Image
{
Source = ImageSource.FromUri(new Uri(filepath)),
Aspect = Aspect.AspectFit,
BackgroundColor = Color.Red,
VerticalOptions = LayoutOptions.Start
};
结果是这样的:
我的目的是缩小图像之间的垂直空间。
解决方案
额外的垂直间距不是由于Grid
's RowSpacing
,而是由于图像引入的填充AspectRatio
。一旦Row
'sHeight
和Column
' 的宽度设置为与Image
' 的纵横比匹配并且AspectRatio
Image 上的 Property 设置为Aspect.Fill
额外的填充应该消失
推荐阅读
- react-native - Expo Android自适应图标未出现
- git - 我的 Gatsby CMS 部署不是我想要的,Google maps gatsby 插件
- javascript - 如何模拟输入文本?Javascript/jQuery, vextab
- windows - 在 IE 中编辑 Word 不打开 Word
- xml - 如何将 MARC21-xml 转换和过滤成 csv?
- ruby-on-rails - Rails 管理员:如何添加助手和使用视图助手?
- javascript - 如何获取任何 subreddit 图片,包括成人图片?不和谐.js
- java - 在 Java 中找不到 REST 服务的 url
- node.js - 需要时对象解构是否会导致 Node.js 中的内存泄漏?
- json - 存在属性时在 json 模式中添加模式验证