如何判断 TextView 文本是否因 singleLine="true" 而被截断?

How to tell if TextView text has been truncated due to singleLine="true"?

我有一个 TextView,我想知道它是否由于 XML.

中的 singleLine="true" 而被截断

有什么想法可以实现这一点而不必传递显示的文本,而仅使用 TextView 检测它?

OP 正在寻找的答案在以下 link 中找到: Check if textview is ellipsized in android

答案基本上就是用这个方法比较文本的长度和椭圆数来判断是否被截断了。

Layout layout = textview1.getLayout();
if(layout != null) {
    int lines = layout.getLineCount();
    if(lines > 0) {
        int ellipsisCount = layout.getEllipsisCount(lines-1);
        if ( ellipsisCount > 0) {
            Log.d(TAG, "Text is ellipsized");
        } 
    } 
}