国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android TextView多行文本(超過3行)使用ellipsize屬性無效問題的解決方法

2020-04-11 12:03:20
字體:
來源:轉載
供稿:網友

布局文件中的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);
  }
  }
});

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 光山县| 靖宇县| 古田县| 崇礼县| 获嘉县| 黎城县| 武冈市| 樟树市| 宣威市| 舞钢市| 神农架林区| 繁峙县| 通化县| 玛纳斯县| 安国市| 化德县| 九龙县| 岳西县| 同仁县| 铜鼓县| 焦作市| 綦江县| 太保市| 紫阳县| 西华县| 沾化县| 云浮市| 周口市| 辽宁省| 安丘市| 庆安县| 灵璧县| 景德镇市| 闵行区| 那坡县| 任丘市| 湖北省| 盖州市| 白城市| 微山县| 东阿县|