Using textView.getLayout (). getEllipsisStart (0) only works if android: singleLine = "true"
Here is a solution that will work if Android: maxLines is installed:
public static String getEllipsisText(TextView textView) {
if (textView==null || TextUtils.isEmpty(textView.getText())) return null;
Layout l = textView.getLayout();
if (l!=null) {
int end = l.getLineEnd(textView.getMaxLines()-1);
return textView.getText().toString().substring(end);
}
return null;
}
Remember: this works after the view is already visible.
Application:
textView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Log.i("test" ,"EllipsisText="+getEllipsisText(textView));
}
});
source
share