有没有办法检查 TextView 的文本是否被截断 [英] Is there a way to check if a TextView's text is truncated

查看:23
本文介绍了有没有办法检查 TextView 的文本是否被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查我的代码中 TextView 的文本是否被截断?

Is there a way to check whether a TextView's text is truncated in my code?

推荐答案

可以使用方法:getEllipsisCount

You can use method: getEllipsisCount

 public static boolean isTextTruncated( String text, TextView textView )
    {
        if ( textView != null && text != null )
        {

            Layout layout = textView.getLayout();
            if ( layout != null )
            {
                int lines = layout.getLineCount();
                if ( lines > 0 )
                {
                    int ellipsisCount = layout.getEllipsisCount( lines - 1 );
                    if ( ellipsisCount > 0 )
                    {
                        return true;
                    }
                }
            }

        }
        return false;
    }

我在以下相关帖子中找到了答案:

I found the answer at the following related post:

检查textview在android中是否为椭圆形

这篇关于有没有办法检查 TextView 的文本是否被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆