布局文件中的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控件属性大全
  2. Android控件属性大全
  3. Android的简易弹幕
  4. Android(安卓)ScrollView 内部控件 layout_margin失效的解决方法
  5. Android(安卓)控件的可见,不可见,隐藏的设置【已解决】
  6. Android控件基本属性介绍
  7. 搜索栏+流式布局+数据库
  8. Android控件基本属性介绍
  9. android学习资料

随机推荐

  1. Android下 PreferenceActivity 的使用
  2. Android的MediaRecorder框架介绍
  3. Android(安卓)Looper
  4. Android中正确自适应屏幕翻转
  5. Android(安卓)Binder(zt)
  6. android设备adb usb驱动安装方法
  7. textview中加链接
  8. Android(安卓)camera 默认显示黑白的问题
  9. Android怎么在控制台输出语句
  10. Android中的ThreadLocal源码解析