当我定义一个TextView在xml,我如何添加一个新的行?\n似乎不起作用。

<TextView
   android:id="@+id/txtTitlevalue"
   android:text="Line1 -\nLine2"
   android:layout_width="54dip"
   android:layout_height="fill_parent"
   android:textSize="11px" />

当前回答

System.getProperty(“line.separator”);这对我很有用。

其他回答

不要相信Visual编辑器。 你的代码在emu中工作。

对我来说,解决方案是在布局中添加以下一行:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    ...
    >

\n在可视编辑器中显示为新行。希望能有所帮助!

RuDrA05的答案很好,当我在eclipse上编辑XML时,它不起作用,但当我用notepad++编辑XML时,它确实起作用。

如果我读取一个用eclipse或notepad++保存的txt文件,也会发生同样的事情

可能和编码有关。

确保你的“n”在“\n”中才能工作。

这很好。检查你的应用程序。

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text 1\nText 2\nText 3"/>