I received it using the following method, which I created as per my requirement.
private void autoScaleTextViewTextToHeight(TextView tv)
{
String s = tv.getText().toString();
float currentWidth = tv.getPaint().measureText(s);
float phoneDensity = this.getResources().getDisplayMetrics().density;
while(currentWidth > (REQUIRED_WIDTH * phoneDensity)) {
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize() - 1.0f);
currentWidth = tv.getPaint().measureText(s);
}
}
source
share