国产探花免费观看_亚洲丰满少妇自慰呻吟_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);
  }
  }
});

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双鸭山市| 琼海市| 莆田市| 怀集县| 上蔡县| 澎湖县| 志丹县| 南和县| 鹤山市| 石柱| 潜江市| 织金县| 乃东县| 任丘市| 保定市| 班戈县| 田东县| 金湖县| 津南区| 平邑县| 喀喇沁旗| 富源县| 象山县| 措勤县| 灌南县| 宁陕县| 荔波县| 东乌| 平凉市| 和林格尔县| 绩溪县| 高陵县| 汉阴县| 贺州市| 普陀区| 江城| 开原市| 太仓市| 广德县| 德庆县| 德庆县|