Android Question drawing an arc

FrankDev

Active Member
Licensed User
Longtime User
Hello,

I would like to draw an arc in the header of an activity.
What is the best way to do this?
A huge circle whose centre is negatively above the top of the activity ?

Regards Frank
 

Attachments

  • bow1.png
    bow1.png
    41 KB · Views: 98

William Lancee

Well-Known Member
Licensed User
Longtime User
Yes. Use B4XCanvas and B4XPath. Of course as a custom header you use full screen, no title, and add your own decorations.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dim headerPanel As B4XView = xui.CreatePanel("")
    headerPanel.Color = xui.Color_Red
    Root.AddView(headerPanel, 0, 0, Root.width, .075 * Root.height)
    Dim cv As B4XCanvas
    cv.initialize(headerPanel)
   
    Dim radius As Float = 2 * Root.Width
    Dim path As B4XPath
    path.InitializeArc(headerPanel.width/2, -radius + headerPanel.height - 5dip, radius, 70, 40)
    cv.DrawPath(path, xui.Color_Blue, True, 0)
       
End Sub

headerExample.png
 
Upvote 2

TILogistic

Expert
Licensed User
Longtime User
just a small adjustment, as requested.
B4X:
    Dim headerPanel As B4XView = xui.CreatePanel("")
    headerPanel.Color = xui.Color_Transparent
    Root.AddView(headerPanel, 0, 0, Root.width, .20 * Root.height)
and
B4X:
headerPanel.SendToBack

1643610713954.png
 
Upvote 2

William Lancee

Well-Known Member
Licensed User
Longtime User
And a small adjustment by me.

Don't forget to invalidate the cv on Android when the drawing is done.
I almost always do, and have to track it down.
 
Upvote 0

FrankDev

Active Member
Licensed User
Longtime User
hi @William Lancee

I need this to draw a header on several activities.

Do I do this for each page ?


Private Sub B4XPage_Created (Root1 As B4XView) Root = Root1 Dim headerPanel As B4XView = xui.CreatePanel("") headerPanel.Color = xui.Color_Red Root.AddView(headerPanel, 0, 0, Root.width, .075 * Root.height) Dim cv As B4XCanvas cv.initialize(headerPanel) Dim radius As Float = 2 * Root.Width Dim path As B4XPath path.InitializeArc(headerPanel.width/2, -radius + headerPanel.height - 5dip, radius, 70, 40) cv.DrawPath(path, xui.Color_Blue, True, 0) End Sub:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Dim headerPanel As B4XView = xui.CreatePanel("")
    headerPanel.Color = xui.Color_Red
    Root.AddView(headerPanel, 0, 0, Root.width, .075 * Root.height)
    Dim cv As B4XCanvas
    cv.initialize(headerPanel)
  
    Dim radius As Float = 2 * Root.Width
    Dim path As B4XPath
    path.InitializeArc(headerPanel.width/2, -radius + headerPanel.height - 5dip, radius, 70, 40)
    cv.DrawPath(path, xui.Color_Blue, True, 0)
    
     invalidate.cv ''?????   <----------------------------------------------------------
      
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Yes, each activity and on each page that you want it, BUT only once for each.

Are you using B4XPages? It will save you a lot of headaches.
There is only one activity (and you won't need a header there), a simple life cycle, and lots of pages (each can be thought of as screen/form).
The code above should be put in the B4XPage_Created sub of each page.

If you are not using B4XPages, then you need to modify the code by using "Activity" instead of "Root" and put the code in each Activity.
Put it in Activity_Create, but not just the first time. It needs to be done each time the Activity is created (which happens when Resumed after a Pause)
That's why B4XPages is better.

P.S. You will need the XUI library.

And it is:
B4X:
cv.Invalidate
 
Last edited:
Upvote 0
Top