Find if ellipsis is shown in TextView
1 min readAug 13, 2018
Many times we need to know if my textview has shown ellipsis or not and if yes add “Show more” button/link next to it to expand and show entire data.
Below is a util method which will do the trick.
private boolean hasEllipsis(View view) {
final TextView description = (TextView) view.findViewById(R.id.details_text_view);
if (description == null) {
return false;
}
boolean hasLongContent = false;
Layout descriptionLayout = description.getLayout();
if (descriptionLayout != null) {
int lines = descriptionLayout.getLineCount();
if (lines > 0) {
if (descriptionLayout.getEllipsisCount(lines - 1) > 0) {
hasLongContent = true;
} else {
hasLongContent = false;
}
}
}
return hasLongContent;
}