【发布时间】:2011-12-09 03:52:16
【问题描述】:
有没有办法以编程方式将TextView 中的文本设置为两行?
【问题讨论】:
标签: android android-widget textview
有没有办法以编程方式将TextView 中的文本设置为两行?
【问题讨论】:
标签: android android-widget textview
输入\n 换行
This will be\ntwo lines
看起来像
This will be
two lines
另外,请确保 TextViews setsingleline() 未设置为 true
【讨论】:
android:maxLines 限制。
TextView tv = new TextView(this);
tv.setText("First Line \n this is Second Line");
setContentView(tv);
【讨论】:
您可以使用\n 在您的文本视图中插入换行符。
像这样:
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");
希望这会有所帮助。
【讨论】:
singleLine 已弃用,请使用 maxLine = "1"