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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-20 我要评论
想了解android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决办法的相关内容吗,在本文为您仔细讲解android TextView多行文本(超过3行)使用ellipsize属性无效的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:android,TextView,ellipsize,下面大家一起来学习吧。

布局文件中的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);
  }
  }
});

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们