Por si a alguien le interesa.
Dibujamos el contenido de un label en un panel: se busca el tamaño máximo de la fuente del label, para que quepa en el alto de este y después se dibuja en el panel.
Librerías necesarias : JavaObject y StringUtils
Dibujamos el contenido de un label en un panel: se busca el tamaño máximo de la fuente del label, para que quepa en el alto de este y después se dibuja en el panel.
Librerías necesarias : JavaObject y StringUtils
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.
Dim cv As Canvas
Dim pcv As Panel
Dim label1 As Label
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")
pcv.Initialize("")
Activity.AddView(pcv, 50dip,50dip,250dip,30dip)
pcv.Color = Colors.White
cv.Initialize(pcv)
label1.Initialize("")
Activity.AddView(label1, 50dip,170dip,250dip, 30dip)
label1.Text= "Ejemplo de dibujar en un panel, el texto de un label, haciendo wordwrap, basado en un post de Erel "
'https://www.b4x.com/android/forum/threads/wordwrap-to-a-canvas.71712/
label1.TextColor = Colors.Black
label1.Padding = Array As Int (12dip, 0, 12dip, 0)
label1.Color = Colors.white
label1.Gravity = Gravity.CENTER_VERTICAL
label1.TextSize = 20
End Sub
Sub Activity_Click
Dim i, size As Int
Dim su As StringUtils
For i = 20 To 7 Step -1
label1.TextSize = i
size = su.MeasureMultilineTextHeight(label1,label1.Text)
If size < 30dip Then 'alto del label
label1.TextSize = i
Exit
End If
Next
DrawView(cv, label1)
pcv.Invalidate
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub DrawView (cvs As Canvas, v As View)
Dim cjo As JavaObject = cvs
Dim jv As JavaObject = v
jv.RunMethod("draw", Array(cjo.GetFieldJO("canvas")))
End Sub