有没有办法以编程方式将TextView
中的文本设置为两行?
输入\n
以换行
This will be\ntwo lines
看起来会像什么
This will be
two lines
同时,请确保TextView的setSingleLine()
方法未设置为true。
TextView tv = new TextView(this);
tv.setText("First Line \n this is Second Line");
setContentView(tv);
\n
在文本视图中插入换行符。
就像这样:
playing.setText( "STATION: \n" + stations.get( position ) );
txtNextLine.setSingleLine(false);
txtNotActivate.setText("first line\n"+"second line");
singleLine
is deprecated , use maxLine = "1"
- Saurabh Bhandari
android:maxLines
的限制。 - Zon