【问题标题】:Xamarin Forms: Grid of images has too much space between elements row-wiseXamarin Forms:图像网格在元素行之间有太多空间
【发布时间】:2020-09-05 17:28:54
【问题描述】:

我有一个包含 2 列的网格,用于承载图像。

<ScrollView VerticalOptions="Start">
        <Grid
          x:Name="gridLayout"
          RowSpacing="5"
          VerticalOptions="Start">

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

图像是以编程方式添加的,因为我不知道执行之前的数量。 Image 是这样声明的

Image image = new Image
                {
                    Source = ImageSource.FromUri(new Uri(filepath)),
                    Aspect = Aspect.AspectFit,
                    BackgroundColor = Color.Red,
                    VerticalOptions = LayoutOptions.Start
                };

结果是这样的:

Screenshot

我的目的是缩小图像之间的垂直空间。

【问题讨论】:

  • 您是否在添加行时设置了高度?
  • 我认为这是因为您看到了图像方面的差距。尝试将Aspect 设置为填充以检查它是否与它有关
  • @Jason 没有。当我添加它们时,我只指定行号和列号。
  • @zafar 如果我将其更改为填充,则会发生这种情况link。我要看起来像问题的屏幕截图,只是没有空白。
  • 您需要添加 RowDefinitions 来定义行的高度

标签: c# .net xaml xamarin xamarin.forms


【解决方案1】:

额外的垂直间距不是由于GridRowSpacing,而是由于图像AspectRatio引入的填充。一旦RowHeightColumn 的宽度设置为与Image 的纵横比匹配,并且图像上的AspectRatio 属性设置为Aspect.Fill,额外的填充应该消失

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多