Android Question Black edges of label after canvas ClearRect

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Drawing progressbar at the bottom of a label. After that I need to clear this progressbar:

B4X:
Dim i As Int
Dim cvs1 As B4XCanvas

For i = 1 to 100
cvs1.DrawLine(0, lbl.Height - 1, lbl.Width * i/100, lbl.Height - 1, Colors.Red, 1dip)
cvs1.Invalidate
Next

'then after a while (user will press a button), need to clear this progressbar:

cvs1.ClearRect(cvs1.TargetRect)
cvs1.Invalidate
lbl1.Invalidate

The progressbar is cleared, but there are black margins at the left, top and right border.
Any suggestions how this should be done?

RBS
 

PaulMeuris

Active Member
Licensed User


B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As Button
    Private Label1 As Label
    Private Button2 As Button
    Dim cvs1 As B4XCanvas
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    cvs1.Initialize(Label1)
End Sub
Private Sub Button1_Click
    For i = 1 To 100
        cvs1.DrawLine(0, Label1.Height - 5,(Label1.Width/100) * i, Label1.Height - 5, Colors.Red, 5dip)
        cvs1.Invalidate
        Sleep(10)
    Next
End Sub
Private Sub Button2_Click
    Dim rect1 As B4XRect
    rect1.Initialize(0,Label1.Height - 10,Label1.Width,Label1.Height)
    cvs1.ClearRect(rect1)
    cvs1.Invalidate
End Sub
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Tip: move the call to Invalidate outside of the loop.

How are you initializing cvs1? Are you drawing on the label background? Might be better to add a transparent panel above it and draw onto this panel.
Yes, the canvas was added directly to the label.
Have gone with the transparent panel and moved also the cvs1.Invalidate outside the loop and all working fine now.
No idea what exactly caused those black left, top and right margins.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I am not using B4XPages, so my code is different, but I tried your suggestion
I don't use B4XPages, so my code is different, but I tried your suggestion (clearing a smaller rectangle), but couldn't get it to work, the progressbar wasn't cleared.
Have gone with Erel's suggestion to draw the progressbar on a transparent panel, covering the label and that works all fine.
Thanks in any case for the idea.

RBS
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…