maui icon indicating copy to clipboard operation
maui copied to clipboard

Padding on ImageButtons works wrong on Android

Open matzeteo opened this issue 2 years ago • 8 comments

Description

If you add padding to an ImageButton on Android, not only a padding will be set, but also a margin with the size of the padding. The button will therefore become smaller due to the padding. To get the button back to the right size, you then need to set a margin with a negative size.

Steps to Reproduce

  1. Create a new Maui App
  2. Create a Grid
  3. Add a ImageButton to the Grid
  4. Set a Padding on the ImageButton
  5. Add a Button to the Grid to see the Size difference
  6. It should be now like:
 <Grid ColumnDefinitions="*,100,100,*" RowDefinitions="*,100,*">
        <ImageButton Grid.Column="1" Grid.Row="1" Padding="10" BackgroundColor="Aqua" Source="dotnet_bot.png"/>
        <Button Grid.Column="2" Grid.Row="1" Text="testButton" Padding="10" BackgroundColor="Blue" WidthRequest="100" HeightRequest="100"/>
    </Grid>

Link to public reproduction project repository

https://github.com/matzeteo/TestApps.git

Version with bug

8.0 (current)

Last version that worked well

Affected platforms

Android

Affected platform versions

Android 10.0 and up

Did you find any workaround?

Set a margin with the negative value of the padding. But that doesn't work for every Layout structure.

Relevant log output

No response

matzeteo avatar Feb 03 '23 09:02 matzeteo

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Feb 03 '23 15:02 ghost

https://github.com/dotnet/maui/issues/7927

AswinPG avatar Feb 06 '23 08:02 AswinPG

Verified this on Visual Studio Enterprise 17.7.0 Preview 2.0. Repro on Android 13.0-API33 with below Project: TestApp.zip

image

XamlTest avatar Jun 20 '23 07:06 XamlTest

This issue should have been fixed by https://github.com/dotnet/maui/pull/14905 Captura de pantalla 2023-06-20 a las 10 15 14

jsuarezruiz avatar Jun 20 '23 08:06 jsuarezruiz

We found a workaround for our use case by using Aspect="Center" for the ImageButton which scales correctly for only a simple image inside an ImageButton. Not sure if this is a fix for any use case but I guess it's worth trying.

samtun avatar Mar 22 '24 09:03 samtun

I can still observe the issue with newest version of Maui (8.0.10)

awasilik avatar Mar 28 '24 19:03 awasilik

Wow @samtun - Aspect="Center" works. This is a good workaround. Thanks for sharing.

@jsuarezruiz This issue still exists in Maui 8.0.10.

gautambjain avatar Apr 08 '24 12:04 gautambjain

I'm trying to use it with Maui 8 but Padding works only on Windows, not on Android

FrancescoCarraro avatar Apr 16 '24 09:04 FrancescoCarraro

It's still not working on Maui 8.0.21 either. (Aspect="Center" is not working as a workaround) If I modify it at runtime within the debugger at the emulator it works.

Hopefully this is fixed soon, a very essential one to get your imagebutton look well. Probably fixable by making a customhandler but it should work out of the box.

MPoels avatar Apr 30 '24 16:04 MPoels

Aspect="Center" does not workaround the bug. Rather, any change to the button at runtime will cause the XAML hot-reload to refresh the button, which then causes it to render correctly (!?!). However, after restarting the app, it's broken again.

This bug was supposed to be fixed in https://github.com/dotnet/maui/pull/14905 but it either didn't work or was regressed. The PR https://github.com/dotnet/maui/pull/22298 supposedly fixes it again. This latter PR is tagged as both "fixed in 8.0.60" and "fixed in 9.0.0". The bug still exists in 8.0.80, so clearly it was not fixed in 8.0.60. Hopefully it's actually fixed in 9.0.0.........

BlueRaja avatar Aug 09 '24 10:08 BlueRaja

Very sad to see this state of basic controls not working properly in Maui. We are creating an app since last September and failed to ship an MVP because of cosmetic issues like this. Maui is a huge let down at this point. We will wait for .NET 9 at best and then we will never return to Maui. Thanks for this pathetic experience team :-)

xibeat avatar Sep 04 '24 18:09 xibeat