0

Like what method sizeWithFont:constrainedToSize:lineBreakMode: does in iOS. Thanks!

I'm sorry I didn't describe my question clearly. I can get the width and height of a given string with the method Paint.getTextBounds(String text, int start, int end, Rect bounds), but in this way, the given string is drawn in a single line. Now I wanna fix the width of the given string, and calculate the heigth of it.

For example, the given string is "abcdefghijklmn", the textsize is 20sp and the width of the drawn text is fixed to 100dp, then the string should be drawn like below, and I want to calculate the height of it. Please ignore the redundant line break below.

abcde

fghij

klmn

Allan
  • 191
  • 1
  • 10
  • [This should be what you need](https://docs.oracle.com/javase/tutorial/2d/text/measuringtext.html) – hatched Jun 01 '18 at 03:39
  • You have probably more chance to get an answer when you explain what this iOS function does. – Henry Jun 01 '18 at 03:53
  • Are you going to get the offer and rise in one of the activities? Like , .getHeight(); .getWidth(); –  Jun 01 '18 at 03:57
  • Isn't `textView.getHeight()` what you want? – 2hamed Jun 01 '18 at 05:43
  • I need not only calculate the height of the string but also draw it in multiple lines, StaticLayout can solve my problem. https://stackoverflow.com/questions/6756975/draw-multi-line-text-to-canvas/8369690#8369690 – Allan Jun 01 '18 at 05:52
  • Is there a way to calculate the height of the string without drawing it first? – Allan Jun 01 '18 at 06:32
  • 1
    You don't have to draw the `StaticLayout` for it to calculate its height. – Mike M. Jun 01 '18 at 18:13

0 Answers0