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
限制。