Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the first character indent on textview of Android

I am using TextView on Android to display multiline text on screen like the below.

aaaaaaaaaaaaaaaaaaaaaa\n
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n
ccccccccccccccccccccccccccccccccccccccccccccccc\n
dddddddddddddddd\n

If I place it to TextView, I have the below result..

aaaaaaaaaaaaaaaaaaaaaa\n
 bbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbb\n
 cccccccccccccccccccccccc
ccccccccccccccccccccccc\n
 dddddddddddddddd\n

I wish to see.. like below..

aaaaaaaaaaaaaaaaaaaaaa\n
bbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbb\n
cccccccccccccccccccccccc
ccccccccccccccccccccccc\n
dddddddddddddddd\n

I mean I do not need auto indent for first space of each line.
How to remove the auto indent?

like image 856
mooongcle Avatar asked Jun 10 '11 15:06

mooongcle


3 Answers

If you have a string in your Res like this:

<string name="aaaa">aaaaaaaaaaaaaaaaa\n
  bbbbbbbbbbbb\n
  cccccccccccccc
</string>

Just just remove newlines. Your string must looks like:

<string name="aaaa">aaaaaaaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccccc</string>
like image 123
skayred Avatar answered Nov 02 '22 10:11

skayred


Is it ok to display HTML? If yes:

textView.setText(Html.fromHtml("aaaa<br/>bbb<br/>cc<br/>d<br/>"));
like image 23
Toni Toni Chopper Avatar answered Nov 02 '22 09:11

Toni Toni Chopper


if you put \n at the end of each line (amount of characters that fit on the screen on one line), the next one will be indented just like the first. basically you don't get rid of the indentation, but rather indent every line instead.

this works, if you have just a few lines to manage, but if you have a lot of text, you should look for a better solution.

like image 44
Cojan Paul Alexandru Avatar answered Nov 02 '22 09:11

Cojan Paul Alexandru