Android Question How to get the width of the string in lable

ronell

Well-Known Member
Licensed User
Longtime User
I want to change the width of the lable tag with the width of the character to determine the width of the lable

determine the width of the label.text and use it as the width of label, no need to use tags
 
Upvote 0

cxdzbl

Active Member
Licensed User

determine the width of the label.text and use it as the width of label, no need to use tags
Dim canvas1 As Canvas
Dim bmp As Bitmap
bmp.InitializeMutable(1dip,1dip)
'Dim cvs As Canvas
canvas1.Initialize2(bmp)
Dim ws As Float=canvas1.MeasureStringWidth(nr,Typeface.DEFAULT,14)

This method is feasible
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You should not use:
bmp.InitializeMutable(1dip, 1dip)
because on 'old' small devices with a scale of 0.75 you will get an error because 1dip = 0.75 therfore 0.
You should use
bmp.InitializeMutable(2dip, 2dip)
or
bmp.InitializeMutable(1, 1) , but here you get a warning because no dip values.
or
bmp.InitializeMutable(1dip,1dip) 'ignore
ignoring the warning.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…