#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.
Dim su As StringUtils
Private Txtlabel As Label
Dim lblMeasure As Label
Dim cnv As Canvas
Dim verticalpadding As Int
Dim horizontalpadding As Int
Dim scaletype As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pnl As Panel
pnl.Initialize("")
Dim btn2 As Button
btn2.Initialize("btn2")
btn2.Color = Colors.Yellow
Activity.Color = Colors.LightGray
Activity.AddView(btn2,5%x,90%y,40dip,40dip)
Activity.AddView(pnl,0,0, 100%x, 100%y)
Txtlabel.Initialize("")
Txtlabel.Color = Colors.white
Activity.AddView(Txtlabel,0,0,0,0)
Txtlabel.Typeface = Typeface.DEFAULT
Txtlabel.TextColor = Colors.black
cnv.Initialize(pnl)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btn2_click
resize_and_addtxt
Dim r As Reflector, DrwRect As Rect
r.Target = Txtlabel.background
DrwRect.Initialize(0, 0, 0, 0)
r.RunMethod4("getPadding", Array As Object(DrwRect), Array As String("android.graphics.Rect"))
verticalpadding = DrwRect.Top + DrwRect.Bottom
Txtlabel.Height = Max(20dip,su.MeasureMultilineTextHeight(Txtlabel,Txtlabel.text)+verticalpadding)
End Sub
Sub resize_and_addtxt
Txtlabel.text = Txtlabel.text & " test"
If (cnv.MeasureStringWidth(Txtlabel.text,Txtlabel.Typeface,16)> 85%x) Then
Txtlabel.Width = 85%x
Else
Txtlabel.Width = cnv.MeasureStringWidth(Txtlabel.text,Txtlabel.Typeface,16)
End If
End Sub