手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法
摘要:布局文件中的TextView属性复制代码代码如下:在JAVA代码中控制文本的显示行数复制代码代码如下:ViewTreeObserverobs...

布局文件中的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属性无效问题的解决方法】相关文章:

Android开机自启动服务的实现方法

android intent使用定义标题

android真机调试时无法显示logcat信息的解决方法介绍

Android控件之EditView常用属性及应用方法

Android ListView数据绑定显示的三种解决方法

Android加载图片内存溢出问题解决方法

Android开发之动画实现方法

Android 完全退出应用程序的解决方法

android图库竖屏不显示status bar的解决方法

android将搜索引擎设置为中国雅虎无法搜索问题解决方法

精品推荐
分类导航