0
設置自動斷線選項我在與它長文本 Android應用程序有一個TextView
。如何在Android中的TextView
問題是TextView不會自動斷行到新行。
這是我爲TextView
TextView txt = new TextView(this);
txt.setText("im not a superman and i have many friends not having any powers");
txt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
txt.setTextColor(Color.BLACK);
txt.setPadding(dp(10), dp(10), dp(20), 0);
txt.setSingleLine(false);
txt.setLines(2);
txt.setMaxLines(4);
txt.setTypeface(Typeface.SERIF,Typeface.NORMAL);
上面的代碼不工作 – sivanesan1 2014-10-27 11:49:38
不工作怎麼樣?不編譯或不給你期待的行爲?因爲我相信,代碼編譯,我懷疑你仍然沒有得到在多行的字符串。在這種情況下,你需要確保父視圖的寬度具有特定的寬度(即,它不是「WRAP_CONTENT」),或者設置一個特定的寬度在您tablerow的(例如,一套寬的「20dp」,而不是「MATCH_PARENT」 ) – Fredrik 2014-10-27 12:13:36