Skip to content

[regression/7.0.49] LinearGradientBrush not working on Android in Landscape orientation #16392

@MAUIoxo

Description

@MAUIoxo

Description

In .NET MAUI (Visual Studio 2022 - Version 17.6.5) a LinearGradientBrush is not calculated correctly or calculated at all under Android when Starting in Portrait orientation and switching to Landscape orientation.

The entire scenario including screenshots was discussed on Stackoverflow
https://stackoverflow.com/questions/76762039/lineargradientbrush-not-working-on-android-in-landscape-view

When starting in Portrait orientation and switching to Landscape orientation the LinearGradientBrush gets cut off at the bottom and is not calculated under Android. On iOS it seems to work perfectly (see Screenshots and comments in link above)

Steps to Reproduce

Create a ContentView with a Grid, BackgroundImage and LinearGradientBrush like this. It does not make a difference if using a ScrollView or a Grid inside:

<!-- BackgroundImage and LinearGradient -->
<Image x:Name="BackgroundImage" Grid.Row="0" Source="radiant_gradient.png" Aspect="AspectFill"/>
<ScrollView Grid.Row="0">
    <ScrollView.Background>
        <LinearGradientBrush EndPoint="0,1">
            <GradientStop Color="Transparent" Offset="0.1" />
            <GradientStop Color="White" Offset="1.0" />
        </LinearGradientBrush>
    </ScrollView.Background>
</ScrollView>

<ScrollView x:Name="ScrollView" Grid.Row="0" Grid.RowSpan="2" VerticalScrollBarVisibility="Always" BackgroundColor="Transparent" VerticalOptions="StartAndExpand">

</ScrollView

In Code-Behind "OnSizeAllocated(..)" the size of the BackgroundImage is scaled like this:

protected override void OnSizeAllocated(double width, double height)
{
    base.OnSizeAllocated(width, height);

    if (height > 0)
    {
        BackgroundImage.HeightRequest = height * 0.7;
    }
}

The idea of this is that we have a BackgroundImage and on top of it a nice looking gradient which fades out to the bottom. This should be realized in Portrait orientation (what it does) as well as in Landscape orientation.

In LandscapeOrientation just on Android (not on iOS) the LinearGradient seems to be cut off when starting in Portrait orientation and switching to Landscape orientation

Link to public reproduction project repository

https://github.com/MAUIoxo/LinearGradient_16392
https://stackoverflow.com/questions/76762039/lineargradientbrush-not-working-on-android-in-landscape-view

Version with bug

7.0.49

Last version that worked well

6.0

Affected platforms

Android

Affected platform versions

.NET MAUI with Google Pixel 5 - API 33 (Android 13.0 - API 33) emulator

Did you find any workaround?

No workaround to get the LinearGradientBrush calculated

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

area-drawingShapes, Borders, Shadows, Graphics, BoxView, custom drawingi/regressionThis issue described a confirmed regression on a currently supported versionplatform/androids/needs-reproAttach a solution or code which reproduces the issuet/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions