Android Question Dashed or dotted border style for panel?

sn_nn

Member
Licensed User
Longtime User
Hi, Everybody!

Is It possible in b4a draw a border for panel (with curved corners) in dash-dash or dash-dot style and change style of border dynamically?

Thanks for help!
 

sn_nn

Member
Licensed User
Longtime User
hi, Toby!
This Thread describes vertical or horizontal lines only. I plane to use border of panel with curverd corners for making circles and ellipses with dashed border...
I would like use some method like this: https://www.b4x.com/android/forum/threads/strokedemo.58687/#content
As a result mast be something like this:
1636809933444.png

The example link is here: https://www.android-examples.com/add-dash-dotted-border-around-to-button-in-android/
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Not a very good solution, but maybe it will inspire someone:

1636872422385.png


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ImageView1 As B4XView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim bmp As B4XBitmap = DrawRectRound(ImageView1.Width, ImageView1.Height, 30, xui.Color_White, xui.Color_Blue, 4)
    XUIViewsUtils.SetBitmapAndFill(ImageView1, bmp)
End Sub

Private Sub DrawRectRound(Width As Int, Height As Int, Radius As Int, FillColor As Int, StrokeColor As Int, StrokeWidth As Int) As B4XBitmap

    Dim r As B4XRect
    r.Initialize(5, 5, Width - 10, Height - 10)
    Dim bc1, bc2 As BitmapCreator
    bc1.Initialize(Width, Height)
    bc2.Initialize(Width, Height)
    bc1.DrawRectRounded(r, FillColor, True, 0, Radius)
    
    Dim StartAngle = 0, SweepAngle = 6 As Float
    Dim cx = r.CenterX, cy = r.CenterY As Float
    Dim MaskRadius As Float = Max(r.Width, r.Height) / 2 * 1.5
    Do While StartAngle < 360
        Dim p As BCPath
        p.Initialize(cx, cy)
        p.LineTo(cx + MaskRadius * CosD(StartAngle), cy + MaskRadius * SinD(StartAngle))
        p.LineTo(cx + MaskRadius * CosD(StartAngle + SweepAngle), cy + MaskRadius * SinD(StartAngle + SweepAngle))
        bc2.DrawPath(p, StrokeColor, True, 0)
        StartAngle = StartAngle + SweepAngle * 2
    Loop
    Dim mask As BCBrush = bc1.CreateBrushFromBitmapCreator(bc2)
    bc1.DrawRectRounded2(r, mask, False,  StrokeWidth, Radius)
    Return bc1.Bitmap
End Sub
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
I put a button on top of the ImageView and set button background to transparent, and here is the look I got:
roundButton.jpg


By changing the width, height and radius, you should be able to get different shapes.
 
Upvote 0
Top