Android Question How to create curved bottom border rectangle in android?

ArminKh1993

Active Member
how to create android drawable with perfect curved bottom using code like this :
1625668297752.png


here https://stackoverflow.com/a/44275750
is solution in java but it's using xml
i want it by code(programmatically)
maybe by using canvas
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1625724472139.png


B4X:
Private Sub CreateBackground (pnl As B4XView)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.Height)
    Dim cvs As B4XCanvas
    cvs.Initialize(p)
    cvs.DrawCircle(p.Width / 2, 0, p.Height, 0xFFFF5B5B, True, 0)
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    pnl.AddView(iv.mBase, 0, 0, pnl.Width, pnl.Height)
    iv.mBackgroundColor = xui.Color_Transparent
    iv.Bitmap = cvs.CreateBitmap
    iv.mbase.SendToBack
    pnl.Color = xui.Color_Transparent
    cvs.Release
End Sub

If you are using it multiple times then it will be more efficient to reuse the canvas.
 
Upvote 0

ArminKh1993

Active Member
View attachment 116017

B4X:
Private Sub CreateBackground (pnl As B4XView)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.Height)
    Dim cvs As B4XCanvas
    cvs.Initialize(p)
    cvs.DrawCircle(p.Width / 2, 0, p.Height, 0xFFFF5B5B, True, 0)
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    pnl.AddView(iv.mBase, 0, 0, pnl.Width, pnl.Height)
    iv.mBackgroundColor = xui.Color_Transparent
    iv.Bitmap = cvs.CreateBitmap
    iv.mbase.SendToBack
    pnl.Color = xui.Color_Transparent
    cvs.Release
End Sub

If you are using it multiple times then it will be more efficient to reuse the canvas.
Fantastic, Thank you ?
 
Upvote 0

ArminKh1993

Active Member
View attachment 116017

B4X:
Private Sub CreateBackground (pnl As B4XView)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, pnl.Width, pnl.Height)
    Dim cvs As B4XCanvas
    cvs.Initialize(p)
    cvs.DrawCircle(p.Width / 2, 0, p.Height, 0xFFFF5B5B, True, 0)
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    pnl.AddView(iv.mBase, 0, 0, pnl.Width, pnl.Height)
    iv.mBackgroundColor = xui.Color_Transparent
    iv.Bitmap = cvs.CreateBitmap
    iv.mbase.SendToBack
    pnl.Color = xui.Color_Transparent
    cvs.Release
End Sub

If you are using it multiple times then it will be more efficient to reuse the canvas.
Can u please help me to clear transparent area?
I want just filled area
i want some thing like clipToOutline method
or some thing to remove extra path
imagine this is a panel and have curved bottom and i add some viewes to this panel
then clipToOutline will not works
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Save canvas to use in other views
Dim bmp As B4XBitmap = CreateBackground
B4X:
    Dim bmp As B4XBitmap = CreateBackground
    
    B4XImageView1.SetBitmap(bmp)
    B4XImageView1.mBase.Color = xui.Color_Transparent
    B4XImageView2.SetBitmap(bmp)
    B4XImageView2.mBase.Color = xui.Color_Transparent
    
    Dim iv As B4XImageView = XUIViewsUtils.CreateB4XImageView
    Pane1.AddView(iv.mBase, 0, 0, Pane1.Width, Pane1.Height)
    iv.mBackgroundColor = xui.Color_Transparent
    iv.Bitmap = bmp
    iv.mbase.SendToBack
    Pane1.Color = xui.Color_Transparent

B4X:
Public Sub CreateBackground As B4XBitmap
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 600, 600)
    Dim cvs As B4XCanvas
    cvs.Initialize(p)
    cvs.DrawCircle(p.Width / 2, 0, p.Height, 0xFFFF5B5B, True, 0)
    cvs.Release
    Return cvs.CreateBitmap
End Sub

sample:
1625773888854.png
 
Upvote 0

ArminKh1993

Active Member
Upvote 0
Top