I have a TextView in my android application that has a set width on it. It\'s currently got a gravity of \"center_horitonzal\" and a set textSize (9sp). I pull values to put o
Another way to do this (which might be equivalent) is something like this:
TextView title = new TextView(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int textsize = 30;
setTextSize(textsize);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
while (getMeasuredHeight() > MeasureSpec.getSize(heightMeasureSpec)) {
textsize--;
setTextSize(textsize);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
};
Just a warning that this seems to work, but I just threw it together - might be some edge cases in ways the TextView can be measured.