Android TextView 单行显示且末尾省略号

2020-10-13  本文已影响0人  三天过去了
@Override
protected void onDraw(Canvas canvas) {
    String text = getText().toString();
    int lastCharDown = getLayout().getLineVisibleEnd(0);
    if (text.length() > lastCharDown) {
        text = text.substring(0, lastCharDown - 1);
        text += "…";
        setText(text);
    }
    super.onDraw(canvas);
}
上一篇 下一篇

猜你喜欢

热点阅读