如何检查是否一个TextView字符串被修整(字幕)? [英] How to check if a TextView String has been trimmed (marquee)?

查看:105
本文介绍了如何检查是否一个TextView字符串被修整(字幕)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个的TextView 没有在它的父元素足够的空间,我会显示一个图标。上文字或图标制表将用于调用与满弦警告对话框。所以,我需要知道,如果一个的TextView 已trinmmed。

If a TextView does not have enough space in its parent element, I will show an icon. A tab on that text or the icon will be used to call an alert dialog with the full string. So i need to know if a TextView has been trinmmed.

推荐答案

Claculate的TextView的宽度,并计算出它时便会显示在TextView的文本的宽度。如果文本的宽度更是TextView的宽度,这意味着你必须调用对话框,因为,因为文本将marqued。否则,文字完全贴合在TextView中没有任何问题,所以没有必要对话框。

Claculate the width of TextView and also calculate the width of text which wil be displayed in the textview. If the width of text is more that the width of textView that means your have to call dialog because because the text will be marqued. Otherwise the text completely fit in the TextView without any issue so no need of dialog box.

使用下面的code。

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
//  System.out.println("...111Height..."+mainLayout.getMeasuredHeight());

    isMarqueed("I am fine here. How r u", textView.getWidth(), textView);
    isMarqueed("I am fine", textView.getWidth(), textView);
}


private boolean isMarqueed(String text, int textWidth, TextView tv) { 
    Paint testPaint = new Paint();
    testPaint.set(tv.getPaint());
    boolean isMarquee = true;
    if (textWidth > 0) {
        int availableWidth = (int) (textWidth - tv.getPaddingLeft() - tv.getPaddingRight()-testPaint.measureText(text));
        System.out.println("...available width..."+availableWidth);
//        tv.setText(text);
        isMarquee = false;
    }
    return isMarquee;
}

谢谢 迪帕克

Thanks Deepak

这篇关于如何检查是否一个TextView字符串被修整(字幕)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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