Question

Can I set property of Textview like justify?

I want to set TextView property like right align, left align, of justify

 21  73584  21
1 Jan 1970

Solution

 17

No, you can't set the property like gravity. But still you can set the justification to your text by taking webview instead of text view.

You may refer to this.

2012-09-01

Solution

 11

What I understand from your question is, you want to know, how to set the alignment of text inside a TextView. You can align text in TextView to left, right, or center.

To do it from your layout (XML) file, use the following attribute in your layout file;

android:gravity=alignment

where,

alignment can be

  • left to align text to left
  • right to align text to right
  • center to center the text

To do the same from code, use the following;

TextView textRegion = (TextView) findViewById(R.id.textRegion);
textRegion.setGravity(gravity);

where,

gravity =

Gravity.LEFT to align to left
Gravity.RIGHT to align to right
Gravity.CENTER to center the text

Note that, justify is not available yet for text alignment in TextView.

Update as of Android 8 (Oreo, API Level 26):
Justification is now possible but look quite jagged at right end.
See setJustificationMode

2011-05-12