Android TextView 設置了maxLines但是不生效的可能原因分析

Android TextView 設置了maxLines但是不生效的可能原因分析

  1. 檢查是否設置了 android:ellipsize=“end” 屬性
  2. 檢查代碼中是否有如下類型的代碼:

錯誤代碼:
不應該在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);
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章