当前位置: 移动技术网 > IT编程>移动开发>Android > android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法

android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

剑灵宠物美容师,西安seo培训,让梦冬眠伴奏

布局文件中的textview属性

复制代码 代码如下:

<textview
android:id="@+id/businesscardsingle_content_abstract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margintop="5dp"
android:linespacingmultiplier="1.0"
android:lines="6"
android:text="@string/agrinbusiness_content"
android:textcolor="#7f7f7f"
android:textsize="13sp" />

 

 在java代码中控制文本的显示行数

复制代码 代码如下:

viewtreeobserver observer = textabstract.getviewtreeobserver(); //textabstract为textview控件
observer.addongloballayoutlistener(new ongloballayoutlistener() {

@override
public void ongloballayout() {
viewtreeobserver obs = textabstract.getviewtreeobserver();
obs.removeglobalonlayoutlistener(this);
if(textabstract.getlinecount() > 6) //判断行数大于多少时改变
  {
    int lineendindex = textabstract.getlayout().getlineend(5); //设置第六行打省略号
    string text = textabstract.gettext().subsequence(0, lineendindex-3) +"...";
    textabstract.settext(text);
  }
  }
});

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网