如:需要顯示的內容 : String str = 顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行
兩行顯示不下時顯示效果 :”顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行顯示顯示兩行兩行...“
代碼 :
textView.setText(str ); //先設置文案
xml 設置
android:ellipsize="end"
android:maxLines="2"
異步獲取
textView.post({
//獲取省略的字數
Layout ly = view.getLayout();
int ellipsisCount = ly.getEllipsisCount(view.getLineCount() - 1);
if(ellipsisCount>0){
//計算顯示的個數
int showCount = str .length() - ellipsisCount;
//截取顯示的文案,拼接...
String tempStr = "“" + str .substring(0,showCount)+"...”";
view.setText(tempStr);
}})