AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

Unable to change width of Android's 'PayButton'

Open DevonHansen opened this issue 8 months ago • 2 comments

Android framework version

net9.0-android

Affected platform version

.NET 9.0.103, VS 2022 17.12.5, Xamarin.GooglePlayServices.Wallet 119.4.0.4

Description

I'm attempting to inject the native Google Pay button into our MAUI system using Handlers with a custom control. Albeit I got it working functionally, the width of the button doesn't respect the parent's width.

I have tried multiple means of changing the width.

From changing HorizontalOptions on the control itself:

<controls:DigitalWalletButton HorizontalOptions="Fill"/>

To modifying the handler's return to include LayoutParameters to specifically match the parent layout:

var payButton = new PayButton(context)
{
    LayoutParameters = new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.MatchParent,
        ViewGroup.LayoutParams.WrapContent)
    {
        Gravity = GravityFlags.CenterHorizontal
    }
};

I've even looked at using Android.Views.View.Post to attempt to realign these after rendering:

payButton.Post(() =>
{
    // Ensure the parent layout is measured
    var parent = payButton.Parent as ViewGroup;
    if (parent != null && parent.MeasuredWidth > 0)
    {
        payButton.LayoutParameters.Width = parent.MeasuredWidth;
    }
    else
    {
        payButton.LayoutParameters.Width = ViewGroup.LayoutParams.MatchParent;
    }
    payButton.RequestLayout();
});

This still doesn't work, and no matter what I do it always sets the PayButton's width to 300. Attached a minimal example in reproduction steps (this example is using just the LayoutParameters method).

Steps to Reproduce

  1. Download ZIP file attached
  2. Extract
  3. Run on Android (iOS has not been implemented). MauiDigitalWallets.zip

Did you find any workaround?

No response

Relevant log output


DevonHansen avatar May 07 '25 13:05 DevonHansen

Thanks for the feedback and repro sample. I will try to see what is going on ASAP.

moljac avatar May 08 '25 07:05 moljac

Any further news on this?

DevonHansen avatar Jul 24 '25 08:07 DevonHansen