android textview ellipsis

Cómo usar puntos suspensivos personalizados en Android TextView



ellipsis (1)

Finalmente lo he logrado de esta manera (puede que no sea el mejor):

private void setLabelAfterEllipsis(TextView textView, int labelId, int maxLines){ if(textView.getLayout().getEllipsisCount(maxLines-1)==0) { return; // Nothing to do } int start = textView.getLayout().getLineStart(0); int end = textView.getLayout().getLineEnd(textView.getLineCount() - 1); String displayed = textView.getText().toString().substring(start, end); int displayedWidth = getTextWidth(displayed, textView.getTextSize()); String strLabel = textView.getContext().getResources().getString(labelId); String ellipsis = "..."; String suffix = ellipsis + strLabel; int textWidth; String newText = displayed; textWidth = getTextWidth(newText + suffix, textView.getTextSize()); while(textWidth>displayedWidth){ newText = newText.substring(0, newText.length()-1).trim(); textWidth = getTextWidth(newText + suffix, textView.getTextSize()); } textView.setText(newText + suffix); } private int getTextWidth(String text, float textSize){ Rect bounds = new Rect(); Paint paint = new Paint(); paint.setTextSize(textSize); paint.getTextBounds(text, 0, text.length(), bounds); int width = (int) Math.ceil( bounds.width()); return width; }

Tengo un TextView con maxlines = 3 y me gustaría usar mis propios puntos suspensivos, en lugar de

"Lore ipsum ..."

Necesito

"Lore ipsum ... [See more]"

para darle al usuario una pista de que al hacer clic en la vista se ampliará el texto completo.

Es posible ?

Estaba pensando en comprobar si TextView tiene elipsis y, en tal caso, agregar el texto "[Ver más]" y después de eso establecer puntos suspensivos justo antes, pero no pude encontrar la manera de hacerlo.

Tal vez si encuentro la posición donde se corta el texto, puedo desactivar las elipsis y hacer una subcadena y luego agregar "... [Ver más]", pero nuevamente no sé cómo obtener esa posición.