TextView获取“实际行数”

时间:2019-01-31 18:59:59

标签: java android xml kotlin

我有以下TextView

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:maxLines="3"
    android:text="Large text"
    android:ellipsize="end" />

当我致电textView.getLineCount()时,我总是得到3。但是我想隐藏“实际行数”,因为我正在使用maxLines。我该怎么办?

2 个答案:

答案 0 :(得分:0)

在xml代码中,将其添加到TextView:

android:inputType = "textMultiLine"

答案 1 :(得分:0)

使用TextView.getLayout()访问有关当前正在布置的实际文本的信息。

TextView tv = findViewById(R.id.textView);
int realLines = tv.getLayout().getLineCount();