布局文件中的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 ScrollView 内部控件 layout_margin失效的解决方法
  2. Android 控件的可见,不可见,隐藏的设置【已解决】
  3. Android控件基本属性介绍
  4. Android定义宽高比控件
  5. android中的基本控件
  6. Android 日期控件属性
  7. Android 布局 & 一些控件

随机推荐

  1. [置顶] android orm映射框架(类似hibernat
  2. Android(安卓)Audio and Video
  3. 13-7-13如何修改android的title
  4. Android开机启动分析(一)logo的显示
  5. Android(安卓)Studio 修改 Logcat 颜色
  6. android源代码下载
  7. activity状态的保存和保持(onRetainNonCo
  8. Android(安卓)常用组价申明及使用简集
  9. 华为手机Android(安卓)Studio开发不显示L
  10. android学习轨迹之二:Android权限标签uses