问题
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?
回答1:
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>
回答2:
Is it ok to display HTML? If yes:
textView.setText(Html.fromHtml("aaaa<br/>bbb<br/>cc<br/>d<br/>"));
回答3:
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.
来源:https://stackoverflow.com/questions/6308905/how-to-remove-the-first-character-indent-on-textview-of-android