zoukankan      html  css  js  c++  java
  • android TextView多行文本(超过3行)使用ellipsize属性无效问题的解决方法

    布局文件:

    <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);
      }
      }
    });
     
  • 相关阅读:
    A. Greg and Array 夜
    zoj 2314 Reactor Cooling 夜
    sgu 104. Little shop of flowers 夜
    C. Greg and Friends 夜
    sgu 103. Traffic Lights 夜
    B. Greg and Graph 夜
    B. Yaroslav and Two Strings 夜
    zoj 2313 Chinese Girls' Amusement 夜
    sgu 101. Domino 夜
    hdu 4532 湫秋系列故事——安排座位 夜
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4188012.html
Copyright © 2011-2022 走看看