dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

[Android] image AspectFill is not honored #21368

Open czuck opened 7 months ago

czuck commented 7 months ago

Description

The Image on the left has an Aspect of AspectFit, the one on the right has AspectFill. On Android they are presented the same: image

on iOS the one on the right correctly expands to fill the width of the parent: image

Steps to Reproduce

Create a File New Maui app. Add a c# ContentPage with the following code:

public class MainCodePage : ContentPage
{
    public MainCodePage()
    {
        var layout = new HorizontalStackLayout();
        layout.Children.Add(GetItem(Aspect.AspectFit));
        layout.Children.Add(GetItem(Aspect.AspectFill));
        Content = layout;
    }

    public ContentView GetItem(Aspect aspect)
    {
        var image = GetImage(aspect);
        var content = new ContentView()
        {
            Content = new ContentView()
            {
                Content = image,
                Padding = new Thickness(2, 5, 2, 2),
                BackgroundColor =  Colors.CadetBlue,
                WidthRequest = 84,
                HeightRequest = 44,
            },
            Padding = new Thickness(1),
        };
        return content;
    }

    public Image GetImage(Aspect aspect)
    {
        var image = new Image
        {
            HorizontalOptions = LayoutOptions.Center,
            HeightRequest = 40,
            MinimumHeightRequest = 40,
            Source = "tile_test_pattern.png",
            Aspect = aspect
        };
        return image;
    }

add the following image to your \Resources\images tile_test_pattern

Modify App.Xaml.cs to set the MainPage to this new page. Run the app. This is also an issue using 8.0.14

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

14

Did you find any workaround?

No response

Relevant log output

No response

czuck commented 7 months ago

The steps and sample code are above in the steps to reproduce area. I'll put there here again. You start with an empty file>new Maui app and add one code file.

Create a File New Maui app. Add a c# ContentPage called MainCodePage and paste in the following code:

public class MainCodePage : ContentPage
{
    public MainCodePage()
    {
        var layout = new HorizontalStackLayout();
        layout.Children.Add(GetItem(Aspect.AspectFit));
        layout.Children.Add(GetItem(Aspect.AspectFill));
        Content = layout;
    }

    public ContentView GetItem(Aspect aspect)
    {
        var image = GetImage(aspect);
        var content = new ContentView()
        {
            Content = new ContentView()
            {
                Content = image,
                Padding = new Thickness(2, 5, 2, 2),
                BackgroundColor =  Colors.CadetBlue,
                WidthRequest = 84,
                HeightRequest = 44,
            },
            Padding = new Thickness(1),
        };
        return content;
    }

    public Image GetImage(Aspect aspect)
    {
        var image = new Image
        {
            HorizontalOptions = LayoutOptions.Center,
            HeightRequest = 40,
            MinimumHeightRequest = 40,
            Source = "tile_test_pattern.png",
            Aspect = aspect
        };
        return image;
    }

add the following image to your \Resources\images tile_test_pattern

Modify App.Xaml.cs to set the MainPage to this new page. MainPage = new MainCodePage();

Run the app. This is also an issue using 8.0.14

Zhanglirong-Winnie commented 7 months ago

Verified this issue with Visual Studio 17.10.0 preview2 (8.0.14&8.0.7&8.0.0-rc.2.9530). Can repro on Android platform with above code. Android: image iOS: image

dasunmax89 commented 5 days ago

because merge request is blocked, you can use ImageButton with InputTransparent="True" until it get fixed.