Bug 49311 - HorizontalTextAlignment="Center" looses alignment when scrolled
Summary: HorizontalTextAlignment="Center" looses alignment when scrolled
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: PC Windows
: --- major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-12-08 14:45 UTC by Louis Haußknecht
Modified: 2017-12-18 15:35 UTC (History)
12 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Louis Haußknecht 2016-12-08 14:45:15 UTC
It's a bit odd, but sometimes the alignment of a Label inside a StackLayout inside a Frame (inside a ViewCell) is messed up.

If you scroll, then sometimes the Label is not centered and sometimes it's centered.

Repro: https://github.com/lhaussknecht/CenterBug

Screencast: https://github.com/lhaussknecht/CenterBug/blob/master/assets/centerBug.gif
Comment 1 Louis Haußknecht 2016-12-08 14:49:37 UTC
Maybe it is an regression of #31265?
Comment 2 adrianknight89 2016-12-08 14:58:34 UTC
Does this issue exist in 2.3.3.175?
Comment 3 adrianknight89 2016-12-08 15:07:03 UTC
I suppose it would. Unfortunately, ListView has issues when it comes to scrolling views. Similar issues can be observed on other platforms.
Comment 4 Louis Haußknecht 2016-12-09 08:43:50 UTC
I dug a bit deeper. 

In 2.3.3.152-pre2 it was working!

But with 2.3.3.163-pre3 the issue appeared.
Comment 5 adrianknight89 2016-12-09 18:05:48 UTC
I ran your repro but was unable to reproduce the issue. I ran it on an S6 device. What emulator were you using? Also, does the issue exist on a device?
Comment 6 Louis Haußknecht 2016-12-09 18:56:04 UTC
Ok, tested it on a Huawei P9 (running Android 6). It's really hard to reproduce the bug there. I had to add some more rows to see the error again.

Evidence is here ;) : https://raw.githubusercontent.com/lhaussknecht/CenterBug/master/assets/screenshot.jpg

Maybe it's because of the more powerful hardware or because of Android 6?
Comment 7 adrianknight89 2016-12-09 19:09:28 UTC
Can you set HasUnevenRows="True" on the ListView and see if it fixes anything? I'm able to reproduce the issue without this setting and with multiple labels per row.
Comment 8 adrianknight89 2016-12-09 19:17:13 UTC
Also removing Frame seems to be another workaround. In general, you should make sure your visual tree is as lean as possible. Until this issue is fixed, workarounds are your best option.
Comment 9 Louis Haußknecht 2016-12-09 19:50:20 UTC
Setting HasUnevenRows="True" seems to help. Thanks. 

I'll also check if we can get rid of that Frame.
Comment 10 Louis Haußknecht 2017-02-16 20:10:04 UTC
Sorry, we need to reopen this. Loosing alignment is still a big problem for us!
Comment 11 Pierce Boggan [MSFT] 2017-06-16 16:00:46 UTC
CONFIRMED on latest Xamarin.Forms prerelease 2.3.5.239-pre3. Download the attached repro, click "ADD MORE!", and scroll.

 Seems like it is happening when a GC happens, as every time the alignment messes up, it is because there is a GC pause.
Comment 12 Derek Foulk 2017-06-21 22:10:41 UTC
Just to put in my two cents... I am having this issue while using a Grid inside of a ListView. Even with 'HasUnevenRows' set to 'True', the 'HorizontalTextAlignment' of my Label appears to change from 'End' to 'Start' after the bound data (EtaDate) changes.

Some snippets of my XAML

    <ListView ItemsSource="{Binding FlightPlans}"
              HasUnevenRows="True"
              ItemSelected="ListView_OnItemSelected"
              CachingStrategy="RecycleElement">
    ...
    <Grid ColumnSpacing="7.5"
          RowSpacing="7.5"
          Padding="15">
    ...
    <Label Grid.Row="1" Grid.Column="2"
           Text="{Binding EtaDate, StringFormat='{0:M/d/yyyy}'}"
           HorizontalTextAlignment="End" />
Comment 13 Philippe Leybaert 2017-08-09 14:23:48 UTC
I am experiencing the exact same issue and it has been a problem for a long time. 

When using a label inside a grid, the alignment is "lost" when the label changes as a result of a change in the bound value.

It only seems to happen for data-bound labels when the bound value changes. It seems (need to double check) to work fine when changing the label of the text manually (by setting the .Text property in code)
Comment 14 cunnpole 2017-10-09 11:05:31 UTC
It's not just Data bound elements as I have the same issue with this:
<Label Text="Add" HorizontalTextAlignment="Center" HorizontalOptions="Center" BackgroundColor="Pink" WidthRequest="80" /> 

Text alignment changes between Start and Center as I scroll. HasUnevenRows is true.

I'm almost at the point of giving up on Xamarin with all of the bugs I've been hit with in the last few releases. Can you please focus more on fixing existing issues and less on new features.
Comment 15 Derek Foulk 2017-10-09 18:03:38 UTC
It's frustrating that many of our reported issues go unresolved (sometimes for years at a time). I will say that I have gotten heated when I have to spend a week patching "simple" issues with the platform, but I believe that good things are coming- and Xamarin is still our go-to for cross-platform development (even though UWP is seemingly very, very- very neglected).

We'll see what 3.0 holds for us. I think they've been focusing on that release (thus the 2.X builds have been suffering). If the 3.X releases aren't solid, stable releases, then we will likely be seeking other options in the future as well!

I (personally) am rooting for Xamarin, as there are plenty of days where I find myself enjoying development again (like the good 'ole days) thanks to their labors.
Comment 16 Alexei Humeniy 2017-12-18 12:32:00 UTC
I have an issue which appears to be related. My app has animations on the OnAppearing event and the loss of alignment is happening when the app is coming back from suspend (ie. when switching apps or opening camera). The problem is more common on Android 4 and 5 devices (I have a Huawei P8 Lite and the problem doesn't happen)

It appears to be a performance related problem, like the control has not finished loading before being shown
Comment 17 David Ortinau [MSFT] 2017-12-18 15:35:30 UTC
This issue has been migrated to GitHub Issues. Please subscribe to the issue there for future updates.

https://github.com/xamarin/Xamarin.Forms/issues/1415