Scale text in a view to fit?
You can use the TextUtils.EllipsizeCallback
. When the text gets ellipsized this callback is done by the textview. Here you can set text size smaller than the current.
EDIT : Otherwise you can use TextUtils.ellipsize
this way
while (mText != TextUtils.ellipsize(mText, textPaint, other params)) {
textpaint.setTextSize(textpaint.getTextSize() - 1);
}
This custom function should do it, using TextUtils.ellipsize ...
public static void shrinkTextToFit(float availableWidth, TextView textView,
float startingTextSize, float minimumTextSize) {
CharSequence text = textView.getText();
float textSize = startingTextSize;
textView.setTextSize(startingTextSize);
while (text != (TextUtils.ellipsize(text, textView.getPaint(),
availableWidth, TextUtils.TruncateAt.END))) {
textSize -= 1;
if (textSize < minimumTextSize) {
break;
} else {
textView.setTextSize(textSize);
}
}
}