0

I have drawn one StaticLayout on imageview and I have to write single as well as multiline text. Issue is I have to restrict the user if text crosses the horizontal boundary in case of single line and also restrict the user vertically in case of multiline text is entered.

I have tried comparing mTextLayout.getHeight() > (rect.height()) rect is the current height of the area where static layout boundary will be drawn. But getHeight() is not available for StaticLayout on docs but can be used from Layout class which is giving wrong results.

So is there any way to know when StaticLayout boundary is reached in any direction.

Ravi Yadav
  • 2,296
  • 3
  • 25
  • 32
  • You might take a look at the algorithm used in [Paginating text in Android](https://stackoverflow.com/a/32096884/3290339) – Onik Mar 20 '20 at 12:46
  • I'm not sure how `mTextLayout.getHeight()` returns a wrong value. Does it return 0 or does it really return something like 200 where it should return 300 or something? – Furkan Yurdakul Mar 20 '20 at 12:49
  • @FurkanYurdakul I havent added any single text then also my condition return true – Ravi Yadav Mar 20 '20 at 12:55
  • 1
    I mean the layout itself might have a height, are you defining it with a height or something? Having no text may not mean the layout itself doesn't have a height. Maybe it has top bottom padding and it returns the value of them in total? – Furkan Yurdakul Mar 20 '20 at 13:39
  • Yes I am defining the height based on rect that I have mentioned. And I am calculating the condition on each text entered in static layout by recreating it and using that condition but before I enter the text on just creation of that staticlayout that height is greater than the actual rect. – Ravi Yadav Mar 21 '20 at 18:30

0 Answers0