I am writing an app in which I need to transfer some text to a canvas, the user selects the text from a spinner and can edit it in a edit text box and when completed it is transferred to a canvas and saved with some other graphics as a .png format file which is then emailed off the device.
I need to wrap the text on word boundaries into a space for text on the RH side of the image, what I am looking to find out is there anyway of getting the length of a piece of text in pixels so I can intelligently wrap the text over 5 or 6 lines. I am using the advance drawing Library so place the text on the canvas is not a problem. I know that I can fit 4/5 average length words into each line but words like 'Brilliantly Intelligent “ would cause and over a wrapping issue.
I can t seem to find a split command to split up a line of text into an array of each word using the space as the splitter.
Dim width, height As Float
Dim Canvas1 as Canvas
Dim t As String
t = "Text to write"
width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<-----
height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)
You need to initialze the Canvas with a target view:
B4X:
Dim width, height As Float
Dim Canvas1 As Canvas
Dim t As String
Canvas1.Initialize(Activity)
t = "Text to write"
width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)<<<-----
height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)