在Android上使用textview编写段落

use*_*849 9 android textview

我想写一个段落作为我的移动应用程序的一部分.我该怎么办呢?

net*_*ein 13

使用\n打破行.

例:

TextView t = findViewById(R.id.text);
t.setText("This is the first line\nThis is the second line\nThird line...");
Run Code Online (Sandbox Code Playgroud)


Asi*_*taq 6

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="text_with_paragraphs">
        Can this contain a lot of text? Can it contain \n a newline? Yes, it can.
        Adding a 2nd line like this should work.
        It should not cause parsing errors.
    </string>
<resources>
Run Code Online (Sandbox Code Playgroud)

所以你可以像这样引用它:

android:text="@string/text_with_paragraphs"
Run Code Online (Sandbox Code Playgroud)

参考:http://www.experts-exchange.com/Programming/Smartphones/Android/Q_27925834.html