Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms Image fill width with proper 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?

enter image description here

like image 485
Vorotnyak_Nazar Avatar asked Dec 30 '16 11:12

Vorotnyak_Nazar


1 Answers

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).

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.

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.

Reference

like image 62
Rudi Visser Avatar answered Sep 28 '22 04:09

Rudi Visser