question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Android Image Aspect issues

See original GitHub issue

Description

AspectFill overflows.

Center doesn’t size at all. What is this supposed to do? Xamarin.Forms doesn’t have “Center”.

No aspect or sizing information provided seems to take up more space vertically than needed.

Screenshot_1632856413

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:app="clr-namespace:ControlGallery"
             xmlns:droid="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
             xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
             ios:Page.UseSafeArea="true"
             x:Class="ControlGallery.Pages.ImagePage"
             Title="Image">
    <ContentPage.Resources>
        <Style TargetType="Image">
            <Setter Property="Background" Value="#f1f1f1"/>
        </Style>
    </ContentPage.Resources>
    <ContentPage.Content>
        <ScrollView Margin="0,60,0,0">
            <VerticalStackLayout 
                Spacing="20"
                Padding="{OnPlatform iOS='30,60,30,30', Default='30,90'}">
                <Label Text="Images" 
                           StyleClass="Headline"/>
                <Border Stroke="Black"
                        StrokeThickness="3"
                        HorizontalOptions="Start"
                        >
                    <Border.StrokeShape>
                        <RoundRectangle />
                    </Border.StrokeShape>
                    <Image Source="{StaticResource CircleIcon}"
                           HeightRequest="50"
                           WidthRequest="50"
                           BackgroundColor="Black"
                           />
                </Border>

                <Label Text="Image with 40x40 and #f1f1f1 bg"/>
                <Image Source="dotnet_bot.png" 
                       BackgroundColor="#f1f1f1"
                       HeightRequest="40" WidthRequest="40"/>

                <Label Text="Image with AspectFill 40x100"/>
                <Image Source="dotnet_bot.png" 
                       BackgroundColor="#f1f1f1"
                       HeightRequest="40" 
                       WidthRequest="100"
                       Aspect="AspectFill"
                       />

                <Label Text="Image with AspectFit 40x100"/>
                <Image Source="dotnet_bot.png" 
                       HeightRequest="40" WidthRequest="100"
                       BackgroundColor="#f1f1f1"
                       Aspect="AspectFit"
                       />

                <!--<Label Text="Image with Center 40x100"/>
                <Image Source="dotnet_bot.png" 
                       HeightRequest="40" WidthRequest="100"
                       Aspect="Center"
                       />-->

                <Label Text="Image with Fill 40x100"/>
                <Image Source="dotnet_bot.png" 
                       HeightRequest="40" WidthRequest="100"
                       Aspect="Fill"
                       />

                <Label Text="Online image"/>
                <Image Source="https://aka.ms/campus.jpg" 
                       BackgroundColor="Red"
                       WidthRequest="200"
                       HeightRequest="200"/>

                <Label Text="Image without sizing info"/>
                <Image Source="dotnet_bot.png" HorizontalOptions="Start" />
            </VerticalStackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

Extra space at top and bottom:

image

When the image with Center is uncommented, it overflows and covers other content.

image

Steps to Reproduce

  1. Create new project
  2. Use the XAML above
  3. Observe

Expected Behavior

Images don’t overflow specified sizing

Images are scaled to the specified sizing with the aspect rule.

Sizing is still correct on multiple rotations.

Actual Behavior

I was able to rotate a few times and sizing got worse.

Basic Information

  • Version with issue: pre9/main
  • Platform Target Frameworks:
    • Android: 28

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
VincentBucommented, May 7, 2022

Not repro in 32506.368.main. Here is the screenshot: image

0reactions
VincentBucommented, May 5, 2022

@jfversluis, Here is the screen shot on Android 28 emulator: image

It looks like image with AspectFill 40x100 isn’t rendered successfully. Additionally, I’m using VS 17.3.0 Preview [32427.505.main].

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to scale an Image in ImageView to keep the aspect ratio
Yes, by default Android will scale your image down to fit the ImageView, maintaining the aspect ratio. · You should also see android: ......
Read more >
A guide for Android ImageView ScaleType and ...
The reason is because the image is scaled uniformly so it maintains the aspect ratio but because the image will be equal or...
Read more >
How to Scale an Image in ImageView to Keep the Aspect ...
How to Scale an Image in ImageView to Keep the Aspect Ratio in Android? ... ImageView is used to display image resources like...
Read more >
Support different pixel densities
Avoid using pixels to define distances or sizes. Defining dimensions with pixels is a problem because different screens have different pixel ...
Read more >
Customize an image | Jetpack Compose
Content scale; Clip an Image composable to a shape; Add a border to an Image composable; Set a custom aspect ratio; Color filter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found