Sergey_New Well-Known Member Licensed User Longtime User Mar 2, 2024 #1 To set the label height I use this code B4X: Copy Dim cn As Canvas cn.Initialize(Activity) lbl.Height=cn.MeasureStringHeight("T", Typeface.DEFAULT,14) To display correctly, the height of the label must be doubled. Does it depend on the screen settings? How to do it right?
To set the label height I use this code B4X: Copy Dim cn As Canvas cn.Initialize(Activity) lbl.Height=cn.MeasureStringHeight("T", Typeface.DEFAULT,14) To display correctly, the height of the label must be doubled. Does it depend on the screen settings? How to do it right?
Solution Alexander Stolte Mar 2, 2024 Sergey_New said: To display correctly, the height of the label must be doubled. Click to expand... This is because this function is only for single-line text. Use this code snipped: [B4X] MeasureMultilineTextHeight I was looking for a way to determine the height of a textview when it has multiline text. This function now makes that possible across platforms. From B4J I come from this thread: https://www.b4x.com/android/forum/threads/measure-multiline-text-height.84331/#content Private Sub... www.b4x.com or use just this 2 lines: B4X: Copy Dim su As StringUtils Return su.MeasureMultilineTextHeight(xLabel,xLabel.Text) Note that it only works if the label you are using has its final width and the final font size, only then can the correct height be calculated.
Sergey_New said: To display correctly, the height of the label must be doubled. Click to expand... This is because this function is only for single-line text. Use this code snipped: [B4X] MeasureMultilineTextHeight I was looking for a way to determine the height of a textview when it has multiline text. This function now makes that possible across platforms. From B4J I come from this thread: https://www.b4x.com/android/forum/threads/measure-multiline-text-height.84331/#content Private Sub... www.b4x.com or use just this 2 lines: B4X: Copy Dim su As StringUtils Return su.MeasureMultilineTextHeight(xLabel,xLabel.Text) Note that it only works if the label you are using has its final width and the final font size, only then can the correct height be calculated.
Sergey_New Well-Known Member Licensed User Longtime User Mar 2, 2024 #2 The width also needs to be increased. Attached an example. Attachments test.zip test.zip 3.3 KB · Views: 371 Upvote 0
Alexander Stolte Expert Licensed User Longtime User Mar 2, 2024 #3 Sergey_New said: To display correctly, the height of the label must be doubled. Click to expand... This is because this function is only for single-line text. Use this code snipped: [B4X] MeasureMultilineTextHeight I was looking for a way to determine the height of a textview when it has multiline text. This function now makes that possible across platforms. From B4J I come from this thread: https://www.b4x.com/android/forum/threads/measure-multiline-text-height.84331/#content Private Sub... www.b4x.com or use just this 2 lines: B4X: Copy Dim su As StringUtils Return su.MeasureMultilineTextHeight(xLabel,xLabel.Text) Note that it only works if the label you are using has its final width and the final font size, only then can the correct height be calculated. Attachments test.zip test.zip 3 KB · Views: 369 Upvote 0 Solution
Sergey_New said: To display correctly, the height of the label must be doubled. Click to expand... This is because this function is only for single-line text. Use this code snipped: [B4X] MeasureMultilineTextHeight I was looking for a way to determine the height of a textview when it has multiline text. This function now makes that possible across platforms. From B4J I come from this thread: https://www.b4x.com/android/forum/threads/measure-multiline-text-height.84331/#content Private Sub... www.b4x.com or use just this 2 lines: B4X: Copy Dim su As StringUtils Return su.MeasureMultilineTextHeight(xLabel,xLabel.Text) Note that it only works if the label you are using has its final width and the final font size, only then can the correct height be calculated.
Sergey_New Well-Known Member Licensed User Longtime User Mar 2, 2024 #4 Alexander Stolte said: or use just this 2 lines: Click to expand... Thanks, this code returns the correct label height. Alexander Stolte said: This is because this function is only for single-line text. Click to expand... In my example, I corrected the value in the constructor to SingleLine=True. Nothing has changed, the height will still need to be doubled. Tell me, please, how to set the label width correctly? Upvote 0
Alexander Stolte said: or use just this 2 lines: Click to expand... Thanks, this code returns the correct label height. Alexander Stolte said: This is because this function is only for single-line text. Click to expand... In my example, I corrected the value in the constructor to SingleLine=True. Nothing has changed, the height will still need to be doubled. Tell me, please, how to set the label width correctly?
Alexander Stolte Expert Licensed User Longtime User Mar 2, 2024 #5 Sergey_New said: Tell me, please, how to set the label width correctly? Click to expand... you need to know the maximum amount of space your label can have, then you set this size Upvote 0
Sergey_New said: Tell me, please, how to set the label width correctly? Click to expand... you need to know the maximum amount of space your label can have, then you set this size
Sergey_New Well-Known Member Licensed User Longtime User Mar 2, 2024 #6 Alexander Stolte said: you need to know the maximum amount of space your label can have Click to expand... Need to add border width? There is still a question about the height of the one-line label, but this probably goes to the founding father. Upvote 0
Alexander Stolte said: you need to know the maximum amount of space your label can have Click to expand... Need to add border width? There is still a question about the height of the one-line label, but this probably goes to the founding father.
Alexander Stolte Expert Licensed User Longtime User Mar 2, 2024 #7 Sergey_New said: Need to add border width? Click to expand... but i don't know what you have in mind, so i can't give you any information Upvote 0
Sergey_New said: Need to add border width? Click to expand... but i don't know what you have in mind, so i can't give you any information
Sergey_New Well-Known Member Licensed User Longtime User Mar 2, 2024 #8 Alexander Stolte said: but i don't know what you have in mind: Click to expand... This: Then I didn't understand what it was: Alexander Stolte said: you need to know the maximum amount of space your label can have Click to expand... Upvote 0
Alexander Stolte said: but i don't know what you have in mind: Click to expand... This: Then I didn't understand what it was: Alexander Stolte said: you need to know the maximum amount of space your label can have Click to expand...