Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 正确使用TextUtils.commaEllipsize大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找一些关于如何正确使用TextView的示例代码.

我在谷歌搜索中找到的唯一一件事是test unit for the TextUtils class.

一些指导将不胜感激.

编辑:

我查看了我在这里得到的答案并尝试在我的代码上实现它.我使用了这段代码

TextView title = (TextView) view.findViewById(R.id.listitemThreadstitlE);
    title.setVisibility(View.VISIBLE);

    TextPaint p = title.getPaint();
    String strtitle = "Moe,Joe,Isaac,Bethany,Cornelius,Charlie";
    title.setText(strtitlE);
    float avail = p.measureText(strtitlE);
    CharSequence ch = TextUtils.commaEllipsize(strtitle,p,avail,"one more","%d more");
    title.setText(ch);

但结果绝对不是它应该是的.

它更像是:Moe,Betha ……

而不是:Moe,Isaac 3

解决方法

public static CharSequence commaEllipsize (CharSequence text,TextPaint p,float avail,String oneMore,String morE)

参数:

text – 要截断的文本
p – 用于测量文本的Paint
avail – 文本可用的水平宽度
oneMore – 当前语言环境中“1 more”的字符串@H_764_32@more – 当前语言环境中“%d more”的字符串

用法例:

String text = "Apple,Orange,Mango,Banana";
TextView tv = new TextView(context);
float textWidth = tv.getPaint().measureText(text );
String tempStr = TextUtils.commaEllipsize(text,tv.getPaint(),textWidth,"1 more","%d more");
tv.setText(tempStr);

更新:

TextView title = (TextView) view.findViewById(R.id.listitemThreadstitlE);
title.setVisibility(View.VISIBLE);

TextPaint p = title.getPaint();
String strtitle = "Moe,Charlie";
title.setText(strtitlE);
float avail = title.getMeasuredWidth();
CharSequence ch = TextUtils.commaEllipsize(strtitle,"%d more");
title.setText(ch);

大佬总结

以上是大佬教程为你收集整理的android – 正确使用TextUtils.commaEllipsize全部内容,希望文章能够帮你解决android – 正确使用TextUtils.commaEllipsize所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。