布局文件中的TextView屬性
在JAVA代碼中控制文本的顯示行數
@Override
public void onGlobalLayout() {
ViewTreeObserver obs = textAbstract.getViewTreeObserver();
obs.removeGlobalOnLayoutListener(this);
if(textAbstract.getLineCount() > 6) //判斷行數大于多少時改變
{
int lineEndIndex = textAbstract.getLayout().getLineEnd(5); //設置第六行打省略號
String text = textAbstract.getText().subSequence(0, lineEndIndex-3) +"...";
textAbstract.setText(text);
}
}
});
|
新聞熱點
疑難解答
圖片精選