这篇文章介绍了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);
  }
  }
});

更多相关文章

  1. 修改Android系统属性SystemProperties.set("sys.powerctl", "shu
  2. Android(安卓)绑定数据到界面控件
  3. RTC搭建android下三层应用程序访问服务器MsSql-客户端
  4. Android(安卓)Animation 框架
  5. textView 属性总结
  6. Android-Module:ImageView常用XML属性
  7. Android布局之baselineAligned属性
  8. layout中设置图片自适应大小,并且设置最大宽高
  9. android中的UI控制(二)

随机推荐

  1. android hover监控鼠标移动事件
  2. 基于Android客户端的人人网开放平台开发
  3. Development and remote installation of
  4. [Android(安卓)Pro] android 混淆文件pro
  5. 简单的 Android(安卓)拍照并显示以及获取
  6. android 实现定时器
  7. 移动网站开发中常用的10段JavaScript代码
  8. Ubuntu搭建Eclipse+JDK+SDK的Android
  9. android 绘制折线图(AChartEngine)Linechar
  10. android用户界面之按钮(Button)教程实例