Right Align Text in Android Textview

Right align text in android TextView

I think that you are doing this: android:layout_width = "wrap_content"
If this is the case, do this: android:layout_width = "match_parent"

How to right-align text in an Android TextView or EditText?

You should use android:gravity="right". layout_gravity is for the view (EditText) alignment against the container.

Android align textview to right

Actually ur code is working but it will be clear if you give width less than parent, try this change

<TextView
android:id="@+id/textview_example"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:textColor="#474747"
android:text="ABAGSADGDBAJDHADNA"
android:textSize="14sp" />

Android TextView Justify Text

I do not believe Android supports full justification.

UPDATE 2018-01-01: Android 8.0+ supports justification modes with TextView.

HTML text alignment in Android TextView

That is because for some reason Html.fromHtml supports start, center and end as text-align values. It does not match CSS, but that's how it works.

Proof

change

"text-align: right"

to

"text-align: end"

in your inline css

Android TextView Left Align and Right Align Text on the Same Line

If you are trying to avoid creating separate TextView, then you might need to use SpannableString.

I think, the solution is demonstrated here

You might get more idea through this link

How to Align Text To the Right in Android TextView?

Did you try?

<TextView
android:id="@+id/txtItemDay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|right"
android:text="Your text"
android:textColor="@android:color/white"
android:textSize="22sp" />

The problem is:

android:layout_width="wrap_content"

You could not align text in TextView if you set with is wrap_content, please set fill_parent or match_parent or specified witdh.



Related Topics



Leave a reply



Submit