Hello,
I am trying to set a button's width to accommodate it's text by using the MeasureStringWidth method. Below is my code. Apparently, I am doing something wrong, because the resulting button's width is only about a half of text's width.
I am trying to set a button's width to accommodate it's text by using the MeasureStringWidth method. Below is my code. Apparently, I am doing something wrong, because the resulting button's width is only about a half of text's width.
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim pnl As Panel
pnl.Initialize("")
Activity.AddView(pnl,0,0, 100%x, 100%y)
Dim cvs As Canvas
cvs.Initialize(pnl)
Dim btn As Button
btn.Initialize("")
btn.Text = "Hello Friends"
btn.TextSize = 14
Dim TextWidth As Int = cvs.MeasureStringWidth("Hello Friends", Typeface.DEFAULT, 14)
pnl.AddView(btn, 10dip, 10dip, TextWidth, 40dip)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub