【问题标题】:TextView get "Real number of lines"TextView 获取“实际行数”
【发布时间】:2019-06-25 07:44:59
【问题描述】:

我有以下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。我该怎么做?

【问题讨论】:

    标签: java android xml kotlin


    【解决方案1】:

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

    android:inputType = "textMultiLine"
    

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      相关资源
      最近更新 更多