TextView get size before it is displayed.

I am about to ‘port’ an app that I have previously produced for iOS (natively in Xcode using Swift 3).

Part of this app allows users to draw shapes by dragging their finger over the screen – these shapes can be any size they like. They can then choose to add some text to the shape. In ios, if the text that the user has entered, results in a UILabel size that is beyond a certain threshold (based on the size of the shape they have drawn) we need to display some alternate text in the box. The user then taps and sees the full text (this is a very brief synopsis of what is going but hopefully it is clear enough).

In iOS I can simply call SizeToFit then get the text box dimensions.

In the past using Android, I have been unable to get the size of a TextView before it is actually drawn to the screen. Is there a way of achieving this without first drawing the control?

This all happens at runtime – the background and various other controls are drawn to the screen when it is initially displayed.

Tagged:
Sign In or Register to comment.