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

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

当前回答

你可以通过简单地在activity.main.xml的线性布局中添加android:orientation="vertical"来获得下一行的文本

其他回答

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

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

旁注:使用大写文本

android: inputType = textCapCharacters”

或类似的似乎阻止了\n的工作。

一种方法是使用Html标签::

txtTitlevalue.setText(Html.fromHtml("Line1"+"<br>"+"Line2" + " <br>"+"Line3"));

也可以加上&lt;br&gt;而不是\n。

然后你可以添加文本到TexView:

articleTextView.setText(Html.fromHtml(textForTextView));

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