先看效果如下:
简单代码示例:
tvMark 介绍
tvMore 更多 按钮
tvMark.setText(TextUtils.isEmpty(video.getContent()) ? "暂无介绍" : video.getContent());
tvMark.post(new Runnable() {
@Override
public void run() {
Layout layout = tvMark.getLayout();
if (layout != null) {
int lines = layout.getLineCount();
if (lines > 0) {
int ellipsisCount = layout.getEllipsisCount(lines - 1);
if (ellipsisCount > 0) {
CharSequence markText = tvMark.getText();
CharSequence charSequence = markText.subSequence(0, markText.length() - ellipsisCount-2);
tvMark.setText(charSequence + "... ");
tvMore.setVisibility(View.VISIBLE);
} else {
tvMore.setVisibility(View.GONE);
}
}
}
}
});