如何删除Android TextView上的第一个字符缩进

发布于 2024-11-15 03:56:16 字数 597 浏览 4 评论 0原文

我在 Android 上使用 TextView 在屏幕上显示多行文本,如下所示。

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

如果我将它放置到 TextView,我会得到以下结果..

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

我希望看到..如下所示..

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

我的意思是我不需要为每行的第一个空格自动缩进。
如何去掉自动缩进?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情归归情 2024-11-22 03:56:16

如果你的Res中有一个像这样的字符串:

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

只需删除换行符即可。您的字符串必须如下所示:

<string name="aaaa">aaaaaaaaaaaaaaaaa\nbbbbbbbbbbbb\ncccccccccccccc</string>

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>
愁杀 2024-11-22 03:56:16

\n 放在新行前面,

aaaaaaaaaaaaaaaaaaaaaa
\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
\nccccccccccccccccccccccccccccccccccccccccccccccc
\ndddddddddddddddd

Put the \n in front of the new line,

aaaaaaaaaaaaaaaaaaaaaa
\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
\nccccccccccccccccccccccccccccccccccccccccccccccc
\ndddddddddddddddd
杯别 2024-11-22 03:56:16

可以显示HTML吗?如果是:

textView.setText(Html.fromHtml("aaaa<br/>bbb<br/>cc<br/>d<br/>"));

Is it ok to display HTML? If yes:

textView.setText(Html.fromHtml("aaaa<br/>bbb<br/>cc<br/>d<br/>"));
星光不落少年眉 2024-11-22 03:56:16

如果将 \n 放在每行末尾(一行上适合屏幕的字符数),则下一行将像第一行一样缩进。基本上你不会去掉缩进,而是缩进每一行。

如果您只有几行需要管理,那么这是可行的,但如果您有很多文本,则应该寻找更好的解决方案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文