如何在TextView中获取椭圆化文本

ade*_*190 9 java android truncate textview

如何将Android截断的文本转换为省略号?

我有一个textview:

<TextView
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:singleLine="true"
    android:text="Um longo texto aqui de exemplo" />
Run Code Online (Sandbox Code Playgroud)

在设备上,此TextView显示如下:

"Um longo texto a..."

我如何获得其余文本?

我正在寻找像getRestOfTruncate()"qui de exemplo"这样的东西.

Sud*_*lan 8

String text = (String) textView.getText().subSequence(textView.getLayout().getEllipsisStart(0), textView.getText().length());
Run Code Online (Sandbox Code Playgroud)

  • 这只有在我有`android:singleLine ="true"`时才有效.如果我将它设置为`false`并将`android:maxLines`设置为除`之外的某个数字,则此方法总是返回整个文本,就好像它根本没有省略. (4认同)