Android Question Draw round border with gradient

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi to all! I tried different times to search on forum, but i don't find nothing. Is possible to draw this?

tempsnip.png


Many thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2018-06-05_19.01.21.png


Using XUI and BitmapCreator libraries:

B4X:
Sub DrawBorder (v As B4XView, clrs() As Int)
   Dim xui As XUI
   v.Color = Colors.Transparent
   Dim cvs As B4XCanvas
   cvs.Initialize(v)
   Dim p As B4XPath
   Dim r As B4XRect
   r.Initialize(0, 0, v.Width, v.Height)
   p.InitializeRoundedRect(r, 10dip)
   cvs.ClipPath(p)
   Dim bc As BitmapCreator
   bc.Initialize(v.Width / xui.Scale, v.Height / xui.Scale)
   bc.FillGradient(clrs, bc.TargetRect, "TOP_BOTTOM")
   cvs.DrawBitmap(bc.Bitmap, cvs.TargetRect)
   cvs.RemoveClip
   r.Initialize(8dip, 8dip, v.Width - 8dip, v.Height - 8dip)
   p.InitializeRoundedRect(r, 8dip)
   cvs.ClipPath(p)
   cvs.ClearRect(cvs.TargetRect) 'this will not work in B4J as ClearRect ignores the clipped path. It can be done with an extra step.
   cvs.RemoveClip
   cvs.Invalidate
   cvs.Release
End Sub
 
Upvote 0
Top