Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将TextView中的文本设置为两行?_Android_Android Widget_Textview - Fatal编程技术网

Android 如何将TextView中的文本设置为两行?

Android 如何将TextView中的文本设置为两行?,android,android-widget,textview,Android,Android Widget,Textview,有没有办法通过编程将TextView中的文本设置为两行?键入\n以获得新行 TextView tv = new TextView(this); tv.setText("First Line \n this is Second Line"); setContentView(tv); This will be\ntwo lines 看起来像 This will be two lines 另外,请确保textviewsetsingleline()未设置为true您可以使用\n在textview中

有没有办法通过编程将
TextView
中的文本设置为两行?

键入
\n
以获得新行

TextView tv = new TextView(this);
tv.setText("First Line \n this is Second Line");
setContentView(tv);
This will be\ntwo lines
看起来像

This will be
two lines

另外,请确保textview
setsingleline()
未设置为true

您可以使用
\n
在textview中插入换行符

像这样:

playing.setText( "STATION: \n" + stations.get( position ) );

确保TextView有几行xml代码:

android:lines=“2” android:singleLine=“false”

默认情况下,
android:singleLine
为true。因此,您可以在XML或Java代码中进行设置,即:

txtNextLine.setSingleLine(false);
txtNotActivate.setText("first line\n"+"second line");

希望这会有所帮助。

单线
已被弃用,请使用
maxLine=“1”
同时检查您的XML中是否没有
android:maxLines
限制。