How do draw a rounded rectangular border around views?

Inman

Well-Known Member
Licensed User
Longtime User
I have a panel in white color, around which I want to draw a gray rectangular border (with rounded corners). How can I do this?

I tried to do it with 9 patch PNG but unfortunately I have always been pretty bad with image manipulation and so the output was messed up.
 

Inman

Well-Known Member
Licensed User
Longtime User
When I set it as Panel's background, won't it fill the whole Panel background with that color, instead of the border alone?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I just knocked this up quickly, see if it works for you.
 

Attachments

  • plainrect.9.png
    plainrect.9.png
    830 bytes · Views: 640
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Thank you so much for this. This is exactly what I wanted. Looks much much better than what I managed to do myself.
 
Upvote 0

francoisg

Active Member
Licensed User
Longtime User
Try this (won't work for rounded corners though)

B4X:
Public Sub DrawBorder(Target As View, aColor As Int, StrokeWidth As Int)
   Dim c As Canvas
   c.Initialize(Target)
   Dim r As Rect : r.Initialize(0, 0, Target.Width - StrokeWidth, Target.Height - StrokeWidth)
   c.DrawRect(r, aColor, False, StrokeWidth)
   Target.Invalidate
End Sub
 
Upvote 0
Top