question

njsokalski avatar image
0 Votes"
njsokalski asked RobCaplan edited

TextView Ignores textAlignment Property

My Xamarin.Android app recently started ignoring the textAlignment property of all the TextView(s). This started happening very unexpectedly in multiple places with no significant changes in code. Also, the Designer in Visual Studio 2019 still shows the correct rendering, even though the app does not. Here are screenshots of the Designer and Emulator:
105620-screenshot-2021-06-14-234745.png


105667-screenshot-1623728937.png
Here is the code for the TextView & Style Resource:

 <TextView android:layout_row="0" style="@style/PopupHeaderTextViewStyle" android:textAlignment="center" android:text="Player Names"/>

 <style name="PopupHeaderTextViewStyle">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:textAlignment">center</item>
     <item name="android:fontFamily">@font/arialfamily</item>
     <item name="android:textStyle">bold</item>
     <item name="android:textSize">30dp</item>
     <item name="android:textColor">@color/Black</item>
 </style>


Note that the textAlignment property is included in the Style & inline. As previously stated, this issue started occuring in all places, both static & dynamic. Because the issue started in completely unrelated places at the same time, it leads me to believe that it was not caused by my code, but I cannot figure out what could have caused the problem or how to fix it.




dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

njsokalski avatar image
0 Votes"
njsokalski answered

I think I found the solution. In the Application (the class that inherits from Application), I had to add SupportsRtl=true in the Application attribute, as follows:

 [Application(Debuggable = true, SupportsRtl = true)]
 public class ScorePadApplication : Application

If SupportsRtl is set to false or not specified (which is what it was before), it ignored android:textAlignment, but now it works. I don't know why it was working before if this is necessary, but it seems to have solved the problem. Hopefully this can help anyone else that has this problem.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered


Hello,​

Welcome to our Microsoft Q&A platform!

I used your code in my VS 2019 Version 16.10.0, my emulator and xaml previewer are work normally, please see the following screenshot

106064-image.png

You can try to delete following code in your PopupHeaderTextViewStyle

<item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">wrap_content</item>


Then set android:layout_width and android:layout_height directly in TextView

<TextView 
        android:layout_row="0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/PopupHeaderTextViewStyle" 
        android:textAlignment="center" 
        android:text="Player Names"/>


Best Regards,

Leon Lu



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (279.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.