saket / Better-Link-Movement-Method

Attempts to improve how clickable links are detected, highlighted and handled in TextView
Apache License 2.0
783 stars 77 forks source link

Ellipsize doesn't work with Spannable #43

Closed ishaansrm closed 3 years ago

ishaansrm commented 3 years ago

Ellipsize doesn't add ... at end of text with maxLines=4 when setting text with BetterLinkMovementMethod:

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="4"/>

This is a platform issue as well; Ellipsize doesn't work with spannableStrings.

A workaround that seems to work is to use Spannable.SPAN_EXCLUSIVE_EXCLUSIVE flag for .setSpan(), instead of Spannable.SPAN_INCLUSIVE_INCLUSIVE

src: https://stackoverflow.com/a/21652979/2639476

This does seem to work for links at the beginning of text too, so not sure what side-effects the flag change may introduce.

saket commented 3 years ago

Yep, I remember running into this as well. Unfortunately, there's nothing a MovementMethod here can do to workaround this.

DanteAndroid commented 3 years ago

I encounter this problem too. Any updates?

ishaansrm commented 3 years ago

Don't think there's anything the lib can do in this case, refer the stackOverflow link for a workaround