Android TextView 設置了maxLines但是不生效的可能原因分析
- 檢查是否設置了 android:ellipsize=“end” 屬性
- 檢查代碼中是否有如下類型的代碼:
錯誤代碼:
不應該在setText,之後再調用append
textView.setText(str1);
textView.append(",");
textView.append(str2);
參考代碼:
應該使用StringBuilder
StringBuilder addressBuilder = new StringBuilder();
if (!TextUtils.isEmpty(info.business)) {
addressBuilder.append(info.business);
showComma = true;
}
if (!TextUtils.isEmpty(info.shortAddress)) {
if (showComma) {
addressBuilder.append(",");
}
addressBuilder.append(info.shortAddress);
tv.setText(addressBuilder);
}