확인,
TextView tvTextView;
String text = "YOUR LONG TEXT WILL BE HERE", subString = "",
int textViewWidth = 100;
int numChars;
tvTextView.setText(text);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
textViewWidth = displayMetrics.widthPixels; // you need to subtract paddings and margins if needed
Log.d("textview_width", "width " + textViewWidth + " length " + text.length());
Paint paint = tvTextView.getPaint();
for (numChars = 1; numChars <= text.length(); ++numChars) {
if (paint.measureText(text, 0, numChars) >= textViewWidth) {
break;
}
}
subString = text.substring(text.length() + 1 - numChars, text.length());
int dots = subString.split("\\.").length * 2;
if(text.length() <= numChars - 1){
subString = text;
}
else {
subString = text.substring(text.length() + 1 + dots - numChars, text.length());
}
tvTextView.setText(subString);