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 ?
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
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
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.