You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have now found that even if you manually create a MauiTextView like this, it is sized wrong compared to what is expected of StaticLayout or the equivalent .NET AppCompatTextView or TextView:
//ADD "TEXT VIEW" MANUALLY IN ANDROID CODE TO ABSOLUTE LAYOUT
abs.HandlerChanged += delegate {
#if ANDROID
var absTrueView = abs.ToPlatform(abs.Handler.MauiContext) as LayoutViewGroup;
MauiTextView text = new(absTrueView.Context);
var scaledDensity = DeviceDisplay.Current.MainDisplayInfo.Density; //= 2.75 on Pixel 5 emulator
float fontSize = 20;
string testString = "HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO HELLO";
text.Text = testString;
var fontManager = abs.Handler.MauiContext.Services.GetRequiredService<IFontManager>();
var font = Microsoft.Maui.Font.OfSize("montserratextrabold", fontSize);
Android.Text.TextPaint textPaint = new();
text.SetTypeface(font.ToTypeface(fontManager), 0);
text.TextSize = (float)(fontSize);
text.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
absTrueView.AddView(text);
text.Measure(1000, 1000);
Debug.WriteLine("CUSTOM MAUI TEXT MEASURED " + text.MeasuredHeight / scaledDensity + " w " + text.MeasuredWidth / scaledDensity);
#endif
};
This returns the identical same wrong measurements as Maui's Label class which is exhibiting the glitching wrapping behavior. So the problem is certainly still there even with that code above for MauiTextView.
I would like to then add directly a plain Android.Widget.TextView or AndroidX.AppCompat.Widget.AppCompatTextView instead to see how they measure.
I expect these would measure correctly (since they measure fine in .NET Android).
However, I find I cannot add any Android class views directly to the hierarchy. There are no errors, but I won't get the size debug output properly and if I open the APK in Android Studio the hierarchy shows it was not added.
For example, if I change the above from
MauiTextView text = new(absTrueView.Context);
to:
AndroidX.AppCompat.Widget.AppCompatTextView text = new(absTrueView.Context);
or:
Android.Widget.TextView text = new(absTrueView.Context);
And try to parameterize them and add them the same, nothing gets added to the hierarchy and I cannot test the behavior.
I note this is similar for all Android objects. For example if I try to add:
Is this normal behavior? Why (or how) are we prevented from adding Android views directly to the hierarchy? Is something in Maui removing these after they are added? Like garbage collecting or pruning them?
If so, how can we stop this for test purposes? How can we figure out why the MauiTextView is not sizing the same as StaticLayout or the true Android classes AppCompatTextView or TextView?
Furthermore, what if anything might MauiTextView be doing wrong in the above code to not give the same result as AppCompatTextView or TextView in .NET Android code?
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Never mind. I am able to add the Android views (even if Maui is pruning them I can debug their size momentarily) but they are still sizing wrong. I still cannot figure out why.
Description
I am still trying to figure out why Android Labels are sizing, ,clipping and wrapping wrong in Maui as discussed here:
I have now found that even if you manually create a
MauiTextView
like this, it is sized wrong compared to what is expected ofStaticLayout
or the equivalent .NETAppCompatTextView
orTextView
:This returns the identical same wrong measurements as Maui's Label class which is exhibiting the glitching wrapping behavior. So the problem is certainly still there even with that code above for
MauiTextView
.I would like to then add directly a plain
Android.Widget.TextView
orAndroidX.AppCompat.Widget.AppCompatTextView
instead to see how they measure.I expect these would measure correctly (since they measure fine in .NET Android).
However, I find I cannot add any Android class views directly to the hierarchy. There are no errors, but I won't get the size debug output properly and if I open the APK in Android Studio the hierarchy shows it was not added.
For example, if I change the above from
to:
or:
And try to parameterize them and add them the same, nothing gets added to the hierarchy and I cannot test the behavior.
I note this is similar for all Android objects. For example if I try to add:
This also fails, while the Microsoft version succeeds:
Is this normal behavior? Why (or how) are we prevented from adding Android views directly to the hierarchy? Is something in Maui removing these after they are added? Like garbage collecting or pruning them?
If so, how can we stop this for test purposes? How can we figure out why the
MauiTextView
is not sizing the same asStaticLayout
or the true Android classesAppCompatTextView
orTextView
?Furthermore, what if anything might MauiTextView be doing wrong in the above code to not give the same result as
AppCompatTextView
orTextView
in .NET Android code?@jonathanpeppers ?
Thanks for any help.
Version with bug
8.0.3 GA
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
Android
The text was updated successfully, but these errors were encountered: