繁体   English   中英

TextView获得“实际行数”

[英]TextView get “Real number of lines”

我有以下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 我怎样才能做到这一点?

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

android:inputType = "textMultiLine"

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM