-1

The first line is normal ways to show text on textview. How I can show like the second ways? enter image description here

Any help would be much appreciated! Thanks!

binhnt
  • 97
  • 3
  • 11
  • what's is your initial element ? A number or a string ? you could always add some tab between each caracter to obtain the 2nd way. – marcS Mar 25 '15 at 09:28
  • That is String, one line just only 16 characters. I have two line. How I can do it ? – binhnt Mar 25 '15 at 09:31
  • If you want to have direct control over letter spacing, this is possible in Lollipop and above by changing the `letterSpacing` attribute in your `TextView`. Else, consider [this](http://stackoverflow.com/questions/1640659/how-to-adjust-text-kerning-in-android-textview/16429758#16429758) answer by Pedro. – PPartisan Mar 25 '15 at 09:54

2 Answers2

0

If you're looking for text that expands the spaces in between to take up whatever area, that's called "justified text". As far as I know it's not currently supported natively in android. This link has quite a number of workarounds, though, from custom textviews to using webviews.

EDIT

The below method does not appear to work anymore, or at least it didn't when I plugged it in to try it out. I would suggest using a custom view in that case. Refer to the link for more information.

Probably the easiest way would be using a webview (poached from the link):

<!--create a webview in xml-->
<WebView
 android:id="@+id/textContent"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />

and then in your activity you do:

WebView view = (WebView) findViewById(R.id.textContent);
String text; 
text = "<html><body><p align=\"justify\">"; 
text+= "123456789";
text+= "</p></body></html>";
view.loadData(text, "text/html", "utf-8");
Community
  • 1
  • 1
Matter Cat
  • 1,538
  • 1
  • 14
  • 23
-1
String temp = "";
for(int i=0;i<10;i++){
    temp=temp+i+" ";
}
textView1.setText(temp);
Avishek Das
  • 661
  • 1
  • 6
  • 20