Android Question SetColorAndBorder - lineDash

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello, I would like to create a LineDash border for a view. Can you please help me with this?
 

Attachments

  • ioVGu.png
    ioVGu.png
    24.9 KB · Views: 130

PaulMeuris

Active Member
Licensed User
Create a bitmap with paint.net (size = 300 wide, 50 high, dashed rectangle, transparent background)
Add the file to the Files tab in the project (border_dashed.png)
Use that bitmap to show a dashed border around a label.
With the second label the dashes are different because of the size of the label.
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As Label
    Private cnvs,cnvs1 As B4XCanvas
    Private rect,rect1 As B4XRect
    Private border As Bitmap
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ' first label from layout (width = 150, height = 40)
    Label1.Text = "this is a test"
    Label1.Padding = Array As Int (5dip, 5dip, 5dip, 5dip)
    Label1.SetLayout(10dip,10dip,300dip,50dip)
    border = LoadBitmapResize(File.DirAssets,"border_dashed.png",Label1.Width,Label1.Height,False)
    cnvs.Initialize(Label1)
    rect.Initialize(0,0,Label1.Width,Label1.Height)
    cnvs.DrawBitmap(border,rect)
    cnvs.Invalidate
    ' second label in code
    Dim lbl As Label
    lbl.Initialize("")
    lbl.Text = "this is a second label"
    lbl.Padding = Array As Int (5dip, 10dip, 5dip, 10dip)
    lbl.SetLayout(10dip,100dip,100dip,100dip)
    border = LoadBitmapResize(File.DirAssets,"border_dashed.png",lbl.Width,lbl.Height,False)
    Root.AddView(lbl,10dip,100dip,100dip,100dip)
    cnvs1.Initialize(lbl)
    rect1.Initialize(0,0,lbl.Width,lbl.Height)
    cnvs1.DrawBitmap(border,rect1)
    cnvs1.Invalidate
End Sub
1679548757999.png
 

Attachments

  • border_dashed.png
    border_dashed.png
    508 bytes · Views: 105
Upvote 0
Top