Xamarin Forms图像填充宽度适当的方面 [英] Xamarin Forms Image fill width with proper aspect

查看:185
本文介绍了Xamarin Forms图像填充宽度适当的方面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是xaml(堆栈布局中的图像).一切都是合乎逻辑的:我将Aspect设置为AspectFit,将Horizo​​ntalOptions设置为FillAndExpand.图片宽度必须填满stacklayout的宽度.必须计算高度才能对Aspect成像.

Here is xaml (an image in stacklayout). Everything is logical: I set Aspect to AspectFit and HorizontalOptions to FillAndExpand. Width of image must fill the width of stacklayout. Height must be calculated in order to image Aspect.

<Image BackgroundColor="Fuchsia"
       Aspect="AspectFit"
       Source="{Binding GroupLogo}"
       HorizontalOptions="FillAndExpand"
       VerticalOptions="FillAndExpand"/>

它会填满整个宽度,但它不想绘制全角的图像.为什么?

It fill the width but It doesn't want to draw image full width. Why?

推荐答案

AspectFit像在罐子上所做的那样,它将使整个图像适合View,这可能会使视图的某些部分留空.直接来自Xamarin的文档:

AspectFit does what it says on the tin, it will fit the whole image into the View, which may leave parts of the view empty. Straight from Xamarin's documentation:

缩放图像以适合视图.某些零件可能会留空(信箱).

Scale the image to fit the view. Some parts may be left empty (letter boxing).

您要查找的是AspectFill,它将缩放图像以适合:

What you're looking for is AspectFill, which will scale the image to fit:

缩放图像以填充视图.某些部分可能会被剪裁以填充视图.

Scale the image to fill the view. Some parts may be clipped in order to fill the view.

如果您尝试使图像视图成为图像的高度,则建议在图像的高度上添加HeightRequest.根据我的经验,图像控件似乎无法在Xamarin中自动缩放,因为默认情况下本机控件也似乎不支持该控件.

If you are trying to get the image view to be the height of the image, I'd suggest adding a HeightRequest to the height of the image. Image controls don't seem to automatically scale in Xamarin, in my experience, as the native controls don't appear to support that by default either.

参考

这篇关于Xamarin Forms图像填充宽度适当的方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆