Unfortunately Kirill didn't provide the src code so I did the ResizableButton code myself. Here's the src code.
The important part is the onLayout code:
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final int oldWidth = getMeasuredWidth();
final int oldHeight = getMeasuredHeight();
int newWidth;
float size = mTextSize;
do {
setTextSize(size--);
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
newWidth = getMeasuredWidth();
} while(newWidth > oldWidth);
setMeasuredDimension(oldWidth, oldHeight);
}
Some doubts:
Kirill mentions in his blog post:
As long as the measured width is less than available width – use the left and right parameters passed to onLayout, decrease the text size and repeat.
* It says less than when I am using greater than.
* I am decreasing the font size by 1. I don't know if that is the best way to do this.
What do you guys think?