Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to justify text in a TextView?

This is what i want. first pic

And this is what i have. second pic

In the above pictures we can see that the lines the paragraph is starting from the most start of the page (aligned start). and in the first picture the lines of paragraph also end of the page (aligned end). so this is i want with my TextView, showing in the second picture but i don't know what to do :(

like image 779
Stackoverflower Avatar asked Oct 25 '25 21:10

Stackoverflower


1 Answers

There are two ways in Kotlin until this time:

This feature is introduced in Android version >= 8.0.

1- XML

<TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:justificationMode="inter_word"
       />

2- Programmatically in an Activity:

Android O offers full justification

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
 TextView.setJustificationMode(LineBreaker.JUSTIFICATION_MODE_INTER_WORD);}

However, Android Studio mentions that you can use it for Android Q , but is still works in Android O

like image 65
Mori Avatar answered Oct 28 '25 10:10

Mori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!