1. 程式人生 > >android TextView多行文字(超過3行)使用ellipsize="end"屬性無效問題的解決方法

android TextView多行文字(超過3行)使用ellipsize="end"屬性無效問題的解決方法

<TextView 
android:id="@+id/desc"
android:layout_width="match_parent"
android:layout_height="130px"
android:lineSpacingExtra="2px"
android:textColor="@color/white"
android:textSize="20px"
android:text="@string/desc"
android:maxLines="4"/>          //設定文字最多為4行

if(mDescTextView.getLineCount() > 4){//判斷行數大於多少時改變
int lineEndIndex = mDescTextView.getLayout().getLineEnd(3); //設定第4行打省略號
String text = mDescTextView.getText().subSequence(0, lineEndIndex-3) +"...";
mDescTextView.setText(text);
}