1

I am creating a image editor. To write a text over image, we would like to have text autoresize feature. For the same I would like to calculate height of editText based on

  1. Characters
  2. Width of editText
  3. font-size

I think it will also vary with font-family and font-weight, if so how to consider all these while calculating height of editText.

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
Circle
  • 177
  • 1
  • 14

1 Answers1

1

You can just set up your editText with font needed, then call:

Rect bounds = new Rect(0, 0, 0, 0);
String textToMeasure = "SOME TEXT"; 
Paint textPaint = editText.getPaint();
textPaint.getTextBounds(textToMeasure, 0, textToMeasure.length(), bounds);

then you will get required width and height from bounds.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45