gistfile1.txt private float adjustTvTextSize(TextView tv, int maxWidth, String text) { int avaiWidth = maxWidth - tv.getPaddingLeft() - tv.getPaddingRight() - 10; if (avaiWidth = 0 || StringUtils.isEmpty(text)) { return tv.getPaint().getTex
private float adjustTvTextSize(TextView tv, int maxWidth, String text) { int avaiWidth = maxWidth - tv.getPaddingLeft() - tv.getPaddingRight() - 10; if (avaiWidth <= 0 || StringUtils.isEmpty(text)) { return tv.getPaint().getTextSize(); } TextPaint textPaintClone = new TextPaint(tv.getPaint()); // note that Paint text size works in px not sp float trySize = textPaintClone.getTextSize(); while (textPaintClone.measureText(text) > avaiWidth) { trySize--; textPaintClone.setTextSize(trySize); } tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, trySize); return trySize; }