How to remove the first character indent on textview of Android

穿精又带淫゛_ 提交于 2019-12-10 13:48:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!