关键是初始化时获取到TextView是的行数,然后进一步处理
比如大于5行的就默认收起,
- 代码
//1.3.7折叠字体
tvInfo.post(new Runnable() {
@Override
public void run() {
int tvLine = tvInfo.getLineCount();
Log.e("txtPart", "run: " + txtPart);
if (tvLine > 5) {
tvShowAll.setVisibility(View.VISIBLE);
tvShowAll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isOpen) {
tvInfo.setMaxLines(5);
isOpen = false;
tvShowAll.setText("全文");
} else {
tvInfo.setMaxLines(Integer.MAX_VALUE);
isOpen = true;
tvShowAll.setText("收起");
}
}
});
}
}
});