Unable to change width of Android's 'PayButton'
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
- Download ZIP file attached
- Extract
- Run on Android (iOS has not been implemented). MauiDigitalWallets.zip
Did you find any workaround?
No response
Relevant log output
Thanks for the feedback and repro sample. I will try to see what is going on ASAP.
Any further news on this?