TextView显示显示两行,用" "包含,显示不下的用...

如:需要显示的内容  : String str = 显示显示两行两行显示显示两行两行显示显示两行两行显示显示两行两行显示显示两行两行显示显示两行两行

两行显示不下时显示效果  :”显示显示两行两行显示显示两行两行显示显示两行两行显示显示两行两行...“

代码 :

textView.setText(str ); //先设置文案

xml 设置

android:ellipsize="end"
android:maxLines="2"

异步获取

textView.post({
//获取省略的字数
Layout ly = view.getLayout();
int ellipsisCount = ly.getEllipsisCount(view.getLineCount() - 1);
if(ellipsisCount>0){
//计算显示的个数
int showCount = str .length() - ellipsisCount;
//截取显示的文案,拼接...
String tempStr = "“" + str .substring(0,showCount)+"...”";
view.setText(tempStr);
}})

 

posted @ 2019-07-03 16:29  你好and程序员  阅读(2755)  评论(0编辑  收藏  举报