'Trailing hyphen in Android TextView

I'm experiencing an issue when limiting number (setting maxLines ) of rows and space in an Android TextView with hyphenation (hyphenationFrequency="full"). For example, trying to display the following string Long\u00adstring\u00adfoobar, which contains soft hyphens (\u00ad), in a TextView where the string doesn't fit, yields the following result:

Long-
string...-

Is there any way to not get the trailing hyphen in this case? Is it a Android issue or am I doing something wrong?

Layout code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="example.MainActivity">

    <TextView
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_height="wrap_content"
            android:id="@+id/tv"

            android:hyphenationFrequency="full"
            android:layout_width="50dp"
            android:ellipsize="end"
            android:maxLines="2"
            android:text="Long\u00adstring\u00adfoobar"

            />

</androidx.constraintlayout.widget.ConstraintLayout>

Screenshot of result



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source