Android Question set label height based on its text length

Addo

Well-Known Member
Licensed User
Longtime User
i am trying to set a different font sized to a label i want to make this label height dynamically change based on its text length and size something like whats app expanding the label text based on the text length
 

Addo

Well-Known Member
Licensed User
Longtime User
i have tried the following
B4X:
globalfontsize = "12"
itmheight = Canvas1.MeasureStringHeight(msggtext, Typeface.DEFAULT, globalfontsize)
Label1.TextSize = globalfontsize

Label1.Text = msggtext

label1.Height = itmheight

but the label height does not expanded more than 36

i needed to make its height based on text content but i have failed
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
why are you using MeasureStringHeight if you want to set label based on its length?

try changing your code to this
B4X:
itmheight = Canvas1.MeasureStringWidth(msggtext, Typeface.DEFAULT, globalfontsize)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…