android - 拆分一个字符串,使文本在彼此之下

标签 android string android-layout textview

<分区>

我有一个字符串,它将在我的下一节课中被 intentExtra 提取并设置为多行 TextView 的文本。我想知道是否有一种方法可以将文本分开,使它们位于彼此之下,所以我有这个字符串:

maint = "Here is some info about nothing." +
                "Some more info about nothing." +
                "And a little more about nothing";

所以通常它们会像这样显示在 textView 中:

Here is some info about nothing. Some more info about nothing. And a little more info about nothing.

有没有办法让他们在每一个单独的部分被写入 TextView 后结束该行

像这样:

Here is some info about nothing.
Some more info about nothing.
And a little more about nothing.

对于每个单独的句子使用单独的 TextView 似乎太过分了。

提前致谢

最佳答案

在你想要换行的地方添加/n。

maint = "Here is some info about nothing.\n" +
        "Some more info about nothing.\n" +
        "And a little more about nothing";

您也可以使用 Html 对其进行格式化。在你想要换行的地方添加一个。

maint = "Here is some info about nothing.</br>" +
        "Some more info about nothing.</br>" +
        "And a little more about nothing";

如果你用HTML格式化它,你需要先解析它然后再传递给textview:

myTextView.setText(Html.fromHtml(maint));

关于android - 拆分一个字符串,使文本在彼此之下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9216824/

相关文章:

android - Android Studio 中的 ViewPager 预览布局

java - 如何理解 Realm 在 android 上的行为?

python - 在字符串中查找插入

android - MediaPlayer滞后于手机锁

php - 如何找到字符串中第一个字母 [A-Za-z] 的位置?

javascript - jQuery - 检查字符串是否大于 4 个字符

android - CoordinatorLayout中如何让ViewStub在AppBarLayout下面

android - 如何在 Ice Cream Sandwich 中设置 TabWidget 的样式?

android - 图像识别框架/指南-增强现实

android - 使用 PhoneGap 在 HTML 中显示联系人图像