iOS Question [Solved] B4XRadioButton and canvas

angel_

Well-Known Member
Licensed User
Longtime User
When I use canvas in B4XPage_Resize, the texts of the radio buttons are duplicated

B4X:
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub B4XPage_Resize (Width As Float, Height As Float)
    Log("B4XPage_Resize")
    #if B4i
        Dim r As Rect = B4XPages.GetNativeParent(Me).SafeAreaInsets
        Root.SetLayoutAnimated(0, r.Left, r.Top, Width - r.Right - r.Left, Height - r.Bottom - r.Top)
    #end if

    Resize1(B4XRadioButton1)
    Resize2(B4XRadioButton2)
    CanvasEncabezado(Label1)
End Sub

Sub Resize1(xrbt As B4XRadioButton)
    Dim Height As Int = 30dip
   
    xrbt.mBase.GetView(1).Height = Height
    xrbt.mBase.GetView(1).Width = xrbt.mBase.GetView(0).Height
    xrbt.mBase.GetView(1).top = (Height - xrbt.mBase.GetView(0).Height) / 2
End Sub

Sub Resize2(xrbt As B4XRadioButton)
    Dim Height As Int = 40dip
   
    xrbt.mBase.GetView(2).Height = Height
    xrbt.mBase.GetView(2).Width = xrbt.mBase.GetView(0).Height
    xrbt.mBase.GetView(2).top = (Height - xrbt.mBase.GetView(0).Height) / 2
End Sub

Sub CanvasEncabezado(lbl As B4XView)
    Dim cvsLinea As B4XCanvas
    Dim x1, x2, y1, y2 As Int
    Dim ColorLinea As Int = lbl.TextColor
   
    cvsLinea.Initialize(lbl.Parent)
   
    Dim r As B4XRect = cvsLinea.MeasureText(lbl.Text, lbl.Font)

    x1 = lbl.Left + r.Width + 16dip
    x2 = lbl.Top + lbl.Height / 2
   
    y1 = 100%x
    y2 = lbl.Top + lbl.Height / 2
   
    cvsLinea.DrawLine(x1, x2, y1, y2, ColorLinea, 1dip)
    cvsLinea.Invalidate
    cvsLinea.Release
End Sub

IMG-0610.PNG
 

Attachments

  • TextRbti.zip
    169.8 KB · Views: 127

angel_

Well-Known Member
Licensed User
Longtime User
Use ordinary panel with height 1dip instead of drawing a line.
Thank you

B4X:
Sub CanvasEncabezado(lbl As B4XView)    'ignore
    Dim pnl As B4XView = lbl.Parent
    Dim cvsLinea As B4XCanvas
    Dim x1, x2 As Int
    Dim pnlLine As B4XView = xui.CreatePanel("")
    
    cvsLinea.Initialize(lbl.Parent)
    
    Dim r As B4XRect = cvsLinea.MeasureText(lbl.Text, lbl.Font)
    
    x1 = 2 * 16dip+ r.Width
    x2 = 100%x - 16dip
    
    pnlLine.Color = lbl.TextColor
    pnl.AddView(pnlLine, x1, lbl.Top + lbl.Height / 2, x2 - x1, 1dip)
End Sub
 
Upvote 0
Top