这篇文章介绍了android TextView多行文本(超过3行)使用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);
  }
  }
});

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

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

    <TextView android:id="@+id/desc" android:layout_width="match_parent" android: ...

  2. Android TextView多行文本滚动实现

    Android中我们为了实现文本的滚动可以在ScrollView中嵌入一个TextView,其实TextView自己也可以实现多行滚动的,毕竟ScrollView必须只能有一个直接的子类布局.只要在l ...

  3. Android 开发之异常处理篇(一):SDK Manager 闪退的解决方法

    这个问题困扰了我很久,之前没解决,就放一放.后来我又专门拿了一个下午来找解决方法,终于搞定! 我的解决方法是修改 android.bat,直接指定java.exe所在位置,不用去调用find_java ...

  4. WordPress Import 上传的文件尺寸超过php.ini中定义的upload_max_filesize值--&gt;解决方法。

    參考一: WordPress Importer上传导入备份文件时遇到这样一个错误,提示"上传的文件尺寸超过 php.ini 中定义的 upload_max_filesize 值". ...

  5. 使用Android Studio过程中,停留在“Building ‘工程名’ Gradle project info”的解决方法

    http://www.loverobots.cn/in-the-process-of-using-studio-android-the-solution-of-the-project-info-gra ...

  6. Android高版本联网失败报错:Cleartext HTTP traffic to xxx not permitted解决方法

    前言:为保证用户数据和设备的安全,Google针对下一代 Android 系统(Android P) 的应用程序,将要求默认使用加密连接,这意味着 Android P 将禁止 App 使用所有未加密的 ...

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

    布局文件中的TextView属性 <TextView android:id="@+id/businesscardsingle_content_abstract" androi ...

  8. android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .

    ①  字体设置: 修改代码 :  GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...

  9. Android Studio中Button等控件的Text中字符串默认大写的解决方法

    初学Android的时候,在Android Studio中xml里面添加一个Button.EditText等控件后,它的Text总是会显示大写,即使你输入的字符串是小写也不行,控制字符串大小写的属性是 ...

随机推荐

  1. lamada 表达式之神奇的groupby

    少说话多干活 先定义一个测试用的实体,接下来会用字段Name进行分组的 public class TestToRun { public string Name { get; set; }//名称 pu ...

  2. android编程常见问题-No Launcher activity found!

    新手编程常见的问题: 问题表现: console提示:No Launcher activity found! The launch will only sync the application pac ...

  3. Oracle 删除表分区

    删除表分区(drop partition)    删除表分区包含两种操作,分别是:   Ø 删除分区:alter table [tbname] drop partition [ptname] UPDA ...

  4. 【Asp.Net-- 杂七杂八】的代码

    Request.Url.PathAndQuery public RedirectResult AddToCart(Cart cart, int productId, string returnUrl) ...

  5. Follow Path -》 Unity3d通用脚本

    PathDefinition.cs using UnityEngine; using System.Collections; using System.Collections.Generic; usi ...

  6. DllImport的具体用法

    现在是更深入地进行探讨的时候了.在对托管代码进行 P/Invoke 调用时,DllImportAttribute 类型扮演着重要的角色.DllImportAttribute 的主要作用是给 CLR 指 ...

  7. Choosing Columns and Expressions to Index

    A key is a column or expression on which you can build an index. Follow these guidelines for choosin ...

  8. DJANGO的requirements的运用

    这里记录一下我现在项目的requirements.pip文件,安装命令为: pip install -r requirements.pip 这样一来,所有依赖,全部搞定. Django== djang ...

  9. Android 加载时在actionBar右上角添加一个加载图标

    ①首先要在Activity的  setContentView()方法前调用requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // ...

  10. hdu 4474 Yet Another Multiple Problem

    题意: 找到一个n的倍数,这个数不能含有m个后续数字中的任何一个 题解: #include<stdio.h> #include<string.h> #include<qu ...