3

无法弄清楚如何使图像小于网格中的容器。

即,如果我希望正方形图像是正方形网格单元格大小的 50% 并在单元格内居中,我该怎么做?

4

2 回答 2

0

Either

  1. you set a WidthRequest, HeightRequest, HorizontalOptions="Center" and VerticalOptions="Center" on your image (but this requires a fixed image size)
  2. or you define another Grid into your parent grid cell. The new (child) grid can define 3 rows "Star" and 3 columns "Star" and your image fills the centered cell. The advantage is that your image can be of any size. It will adapt its size to the screen.
于 2020-09-06T21:26:09.473 回答
0

尝试如下设置图像视图的 Horizo​​ntalOptions 和 VerticalOptions 属性,

Image imageView = new ImageView;
imageView.HorizontalOptions = LayoutOptions.StartAndExpand (or) LayoutOptions.CenterAndExpand
imageView.VerticalOptions = LayoutOptions.StartAndExpand (or) LayoutOptions.CenterAndExpand

此外,尝试通过设置图像视图的 Aspect 属性,

imageView.Aspect = Aspect.AspectFit
于 2017-07-03T04:36:31.830 回答