Skip to content

Commit

Permalink
Allow the image handler to measure more accurately WRT aspect ratio (#…
Browse files Browse the repository at this point in the history
…7389)

Fix for issue 2000 on Android
  • Loading branch information
hartez committed May 23, 2022
1 parent 3e37211 commit cf3b399
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Core/src/Handlers/Image/ImageHandler.Android.cs
Expand Up @@ -7,7 +7,18 @@ namespace Microsoft.Maui.Handlers
{
public partial class ImageHandler : ViewHandler<IImage, ImageView>
{
protected override ImageView CreatePlatformView() => new AppCompatImageView(Context);
protected override ImageView CreatePlatformView()
{
var imageView = new AppCompatImageView(Context);

// Enable view bounds adjustment on measure.
// This allows the ImageView's OnMeasure method to account for the image's intrinsic
// aspect ratio during measurement, which gives us more useful values during constrained
// measurement passes.
imageView.SetAdjustViewBounds(true);

return imageView;
}

protected override void DisconnectHandler(ImageView platformView)
{
Expand Down

0 comments on commit cf3b399

Please sign in to comment.