TextView android: ellipsize = "end" issue
En mi aplicación, he ellipsize
d mi TextView
para que si el texto es demasiado grande, se mostrará ...
al final utilizando android:ellipsize="end"
.
Por ejemplo, el texto ABCDEFGHIJKLMNOPQRSTUVWXYZ
se muestra como ABCDEFGHIJ...
Pero cuando el texto es pequeño, como ABCDEF
todavía muestra ...
al final haciendo que el texto parezca AB...
No puedo fijar el ancho de la vista de texto ya que la misma vista de texto se utiliza en otras partes con algunos requisitos de anchura diferentes. ¿Qué debo hacer para que funcione y muestre ...
sólo si el texto es lo suficientemente grande.
- Verticalmente Centro TextView en RelativeLayout
- android: límite de 10 caracteres por línea TextView
- ¿Es mejor usar múltiples SpanObjects o múltiples TextViews en Android?
- Android: Cambio del texto del cuadro de diálogo de progreso
- Imágenes en TextView
- XAMARIN (C #) - ¿Hay una manera de subrayar un TextView mediante programación?
- Actualizar una vista de texto aunque el usuario no esté utilizando mi aplicación
- ¿Cómo puedo evitar que mi TextView se solape?
- ¿Cómo se desplaza el texto con el buscador?
- cómo poner texto bajo vista de imagen
- Incluir un TextView y anular el texto
- ¿Hay una manera de desactivar el ajuste de línea en una vista de lista en android?
- Agregar color "# e3bb87" a StateListDrawable mediante programación
// En su vista de texto
Agregue los siguientes atributos también
android:maxEms="8" android:singleLine="true"
NOTA: puede ajustar el tamaño de ems a la cantidad de caracteres que desea mostrar.
txtvw.setText("The Indian economy is the world's eleventh-largest by nominal GDP and third-largest by purchasing power parity (PPP). " + " Following market-based economic reforms in 1991, India became one of the fastest-growing major economies; " + " it is considered a newly industrialised country. However, it continues to face the challenges of poverty, illiteracy, corruption, malnutrition, and inadequate public healthcare. " + " A nuclear weapons state and a regional power, it has the third-largest standing army in the world and ranks ninth in military expenditure among nations." + " India is a federal constitutional republic governed under a parliamentary system consisting of 28 states and 7 union territories. " + " India is a pluralistic, multilingual, and multiethnic society. " + " It is also home to a diversity of wildlife in a variety of protected habitats."); ViewTreeObserver vto = txtvw.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { ViewTreeObserver obs = txtvw.getViewTreeObserver(); obs.removeGlobalOnLayoutListener(this); if(txtvw.getLineCount() > 1){ int lineEndIndex = txtvw.getLayout().getLineEnd(1); String text = txtvw.getText().subSequence(0, lineEndIndex-3)+"..."; txtvw.setText(text); } } });
- Android notifyDataSetChanged para ExpandableListView no funciona
- Parcelable de Android Longitudes de array incorrectas