Xamarin.forms: Text Alignment on TextView begin reset to Gravity if parent view hidden then shown

Created on 11 Jan 2018  ·  14Comments  ·  Source: xamarin/Xamarin.Forms

Migrated from https://bugzilla.xamarin.com/show_bug.cgi?id=55243

If a view contains a TextView (lives inside a Grid, if that matters) and the parent view is hidden and then reshown, the TextAlignment of the TextView is being reset back to "Gravity", when it was previously set to End.

I've confirmed this happens by adding a check in a custom render.

Odd behavior: if you change the text in the view, the alignment is restored to "End". If you do not change the text, it is reset back to Gravity, instead of retaining the right alignment (End) originally set.

Basic Information

  • Version with issue: 2.3.4.231, 2.5.0

Reproduction Link

b55243.zip

6 inactive high impact Android needs-info ❓ bug

Most helpful comment

I have confirmed this is NOT fixed in 3.1.0.

All 14 comments

This should be fixed in the Shell branch at the very least, can you please confirm?

In fact I think this should be fixed in 3.1.0

I have confirmed this is NOT fixed in 3.1.0.

I have a similar issue but it only occurs if I set Android Target Version to 19 (4.4) or above. Is this the case with others? My app has always supported Android 4.3 (minimum version) so I haven't needed to change the target version until now since Google is forcing us to target 25+.

Same here, with Xamarin.Forms 3.1.0.
StackLayout having child Grid, HorizontalTextAlignment of items in the grid is broken when parent view is set to visible / invisible.

It is disheartening that this bug is still open. I first reported this bug in April 2017 with an accompanying repo solution (the Bugzilla report above).

In Xamarin Forms 3.1, some alignment issues were resolved, but not all. We are now seeing some gravity issues in locations we never saw before, resulting in even more work after Xam Forms 3 upgrade.

It looks like the issue is related to all locations where a label lives inside an autosized container. A column definition that has an "auto" or "star" grid length, or an Absolute Layout with a AutoSize specified on the child add method. My best guess is that rendering performance improvements that were added to Xamarin Forms removed the extra measure/draw events that once existed, and in turn took care of these auto-layout needs.

The only work around I have found is to avoid auto sizing. Do all the math yourself to position your controls within the detected screen width to accommodate all screen sizes and set a WidthRequest on your controls.

@scottkdavis We spent quite a bit of time working on this issue, and unfortunately, it requires a larger effort than we anticipated. It is an important issue, and it is not forgotten. As @jassmith mentioned, the issue is resolved in a feature branch, and we had hoped to be able to incorporate that fix into a service release; however, it depends on other changes made in that branch, so we won't see it land until the shell branch is merged in. Thank you for reporting this issue, and thank you for your patience!

@samhouts Thanks for your response. I understand. I don't envy anyone that needs to make Android do anything consistently. Jason and his team are undertaking a tremendous challenge. However I hope you understand my willingness to spend many hours to create repo solutions has been greatly diminished because of this bug that we continue to struggle with. Since Xamarin Support won't respond to bug reports without a repo solution, this also discourages me to help improve the product by reporting issues. We started using Xamarin Forms the week it was released, and I've had the tremendous honor of working directly with Jason via Skype to fix bugs prior to the Microsoft acquisition. Our UI is very complicated and we often find issues with each update, but I've stopped reporting them. Screen shots of our UI are here. https://play.google.com/store/apps/details?id=com.qonqr.android.blue&hl=en_US

Best of luck. I hope you find a path to releasing the fix.

@samhouts I just ran into this issue. When do you expect to merge in the shell branch?

@samhouts I have a similar issue with regards to HorizontalTextAlignment being lost as I scroll a ListView up and down. It's said that the issue is fixed in the shell branch, but I'm testing the code against v4.0 pre-10. :(

I've got a Label inside a StackLayout inside an auto-width Grid column. The text is data-bound to a view model. I don't see the issue with static text, so data-binding seems to be breaking things here.

I have a Button inside a Grid and when hiding then showing the buttons, the text alignment is reset to its default value. Effect is seen on Android device and emulators of all API levels. Using XF 4.0.0.482894.

This issue doesn't seem to have had any activity in a long time. We're working on prioritizing issues and resolving them as quickly as we can. To help us get through the list, we would appreciate an update from you to let us know if this is still affecting you on the latest version of Xamarin.Forms, since it's possible that we may have resolved this as part of another related or duplicate issue. If we don't see any new activity on this issue in the next 30 days, we'll evaluate whether this issue should be closed. Thank you!

Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!

Was this page helpful?
0 / 5 - 0 ratings