Android Textview ellipsize con varias filas

Estoy tratando de obtener un ellips al final de un textview que tiene varias líneas de texto. El "…" está mostrando pero su en el último espacio en el texto y es otro seguido por otros caracteres. ¿Cómo me aseguro de que el "…" esté siempre al final.

Ver ejemplo de imagen Introduzca aquí la descripción de la imagen

El archivo XML Layout es:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:orientation="horizontal" > <TextView android:id="@+id/nfDateMonth" android:layout_width="64dp" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="8dp" android:layout_marginTop="2dp" android:background="@drawable/topsegment" android:gravity="center" android:text="APR" android:textAllCaps="true" android:textColor="#f2e606" android:textSize="22sp" android:textStyle="bold" /> <TextView android:id="@+id/nfDateDate" android:layout_width="64dp" android:layout_height="wrap_content" android:layout_below="@+id/nfDateMonth" android:layout_marginBottom="10dp" android:layout_marginLeft="10dp" android:layout_marginRight="8dp" android:background="@drawable/bottomsegment" android:gravity="center" android:text="28" android:textSize="22sp" /> <TextView android:id="@+id/nfTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="2dp" android:layout_marginTop="0dp" android:layout_toRightOf="@+id/nfDateMonth" android:text="Half Marathon" android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="16sp" /> <TextView android:id="@+id/nfContent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/nfTitle" android:layout_gravity="left" android:layout_marginBottom="2dp" android:layout_marginRight="16dp" android:layout_marginTop="2dp" android:layout_toRightOf="@+id/nfDateDate" android:ellipsize="end" android:maxLines="2" android:text="Content\nline two line three sadsa dsd dsa dsd big big big sd sad sad sadsadsad asd sad as d asd as das das das das da sd asd asd one two three four five sixx seven" android:textAppearance="?android:attr/textAppearanceMedium" android:textSize="12sp" /> </RelativeLayout> 

Tuve el mismo problema hoy. Es probablemente un error en TextView o TextUtils (método ellipsize). En mi caso es causado por texto con nuevas líneas.

Hay dos soluciones:

  1. Obtener primera línea solamente:
 String longText = "..."; String body = new Scanner(longText).nextLine(); textView.setText(body); 

2. Eliminar todas las líneas nuevas en el texto

 String longText = "..."; String body = longText.replace("\n", "").replace("\r", ""); textView.setText(body); 
  • RecyclerView con elementos de contenido de ajuste
  • GridView o TableLayout?
  • Múltiples tamaños de widgets
  • AppBarLayout.onCreateDrawableState NullPointerException: Intento de obtener longitud de matriz nula
  • Android: windowSoftInputMode = "adjustResize" no hace ninguna diferencia?
  • Agregar vista a disposición relativa detrás de una vista existente provoca parpadeo de la pantalla
  • Alinea horizontalmente dos vistas de texto en un diseño
  • Linear Layout - Diferencia entre el peso y FILL_PARENT
  • ¿Cómo fijar el fondo de imagen de la imagen para el estado diferente?
  • RatingBar se muestra incorrectamente en Android cuando se encuentra en el mismo TableRow que TextView
  • SetMargin Programmatically no funciona correctamente para RelativeLayoutParams
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.