Justify TextView [duplicate]

-1

How can I justify the text of a TextView tag in Android-Studio. I have been reading a thread that they said that they used android:layout_gravity="center_horizontal|center" but nothing, still does not justify.

I have also seen another thread that said that I used github libraries , but before importing libraries to do something as simple as justifying a text I wanted to know if it could be done with a simple option. Thanks

    
asked by Ignacio Belmonte 10.04.2018 в 21:30
source

1 answer

-1

XML design: declares WebView instead of TextView

<WebView
 android:id="@+id/textContent"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />

Java code: set text data in WebView

WebView view = (WebView) findViewById(R.id.textContent);
String text;
text = "<html><body><p align=\"justify\">";
text+= "Este es el texto se justificará cuando se muestre!!!";
text+= "</p></body></html>";
view.loadData(text, "text/html", "utf-8");

Or use this:

android:gravity="center" 

android:gravity="center_horizontal"

And be sure to use android:gravity and NO android:layout_gravity .

Or you just need to do this: setJustificationMode

textView.setJustificationMode(JUSTIFICATION_MODE_INTER_WORD);

default is JUSTIFICATION_MODE_NONE .

  

See also: This library that will provide you with a way to justify the text:

     

Screenshot :

    
answered by 10.04.2018 в 21:34