Android Question Hide a canvas or make it invisible

aedwall

Active Member
Licensed User
Longtime User
I have an EditText and a canvas upon which I draw various shapes. I display one, then the other (each covers the other so the other should not be seen). But when the EditText shows, the canvas is seen in the background. EditText.Visible = False makes the EditText box invisible. What do I do to cause the canvas to be completely hidden? Thank you.
 

aedwall

Active Member
Licensed User
Longtime User
Thank you. Sometimes half the battle is remembering this "strange" terminology. "TargetView" - I guess one possibility is a panel? I'm going to try that based on the SimpleDrawFunctions example project.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I can't get it to work.

Sub Globals
Dim p3 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
p3.Initialize("p3")
Activity.AddView(p3, 0, 30dip, 100%x, 100%y - 60dip)
cvsLayer.Initialize(p3)
End Sub

(not all code shown).

I insert text into the EditText and it displays fine.

I then draw my graphics and the EditText is not visible, but the graphics are. All is well (because I did this: EditText21.Visible = False)

I hit my "Help" button to do this:

p3.Visible = False

EditText21.Visible = True

and I see my EditText and all its text contents, but in the background (opaquely) I still see my graphics. Why doesn't the panel become invisible?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It would be more efficient if you posted your project.
IDE menu File / Export As Zip.

BTW, when you post code you should use code tags:

upload_2018-4-16_23-0-31.png
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
how about filling the "canvas" with transparent?
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
It would be more efficient if you posted your project.
IDE menu File / Export As Zip.

>> BTW, when you post code you should use code tags:


Yes, but there's things in it my boss does not want others to see. Here is my model - it works fine - every time I click the button the p3 panel is visible, then invisible. When I port over the p3 panel to my real project, it simply doesn't work the same way as in this model. It isn't that complicated, yet I can't figure out what is different.:

B4X:
#Region  Project Attributes
    #ApplicationLabel: Simple Draw Functions
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
    Private p3 As Panel
    Private cvsLayer As Canvas
    Private butn1 As ToggleButton
    Private xc, yc, x1, y1, x2, y2, r1, r2, h, w As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
    x1 = 2%x
    w = 30%x
    y1 = 100%y - 55dip
    h = 50dip
    
  p3.Initialize("p3")
    Activity.AddView(p3, 0, 0, 100%x, 85%y)
    cvsLayer.Initialize(p3)

    butn1.Initialize("butn1")
    Activity.AddView(butn1, x1, y1, w, h)
    butn1.TextOn = "Layer" & " ON"
    butn1.TextOff = "Layer" & " OFF"
End Sub

Sub Activity_Resume
    cvsLayer.DrawColor(Colors.Gray)            'draw 2 circles

    xc = 420dip
    yc = 330dip

    r1 = 60dip
    r2 = 50dip

    cvsLayer.DrawCircle(xc, yc, r1, Colors.Blue, True, 3dip)
    cvsLayer.DrawCircle(xc, yc, r2, Colors.Transparent, True, 1dip)
End Sub

Sub butn1_CheckedChange(Checked As Boolean)
    p3.Visible = Not(p3.Visible)
End Sub
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
at least there is a Color Value but i did not testet it.
B4X:
Colors.Transparent
Canvas1.DrawColor(Colors.Transparent)
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I think I must be drawing my graphics on the Activity (background) and not on the panel. How do I get my statements like:

cvsLayer.DrawCircle(center_pt_x, center_pt_y, inner_radius, Colors.Black, True, 2dip)

to draw the circle on my panel (p3) and not on the Activity (background)?

I have this:

Dim p3 As Panel

cvsLayer.Initialize(p3)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
The attached project seems to work as intended. I did nothing special. The drawing happens on the canvas and when I hide the Panel and show the EditText, no bleed through happens. If you are having issues, you need to post your project just like I did and as @klaus requested so others can reproduce your issue.
 

Attachments

  • CanvasTest.zip
    9.3 KB · Views: 180
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
The attached project seems to work as intended. I did nothing special. The drawing happens on the canvas and when I hide the Panel and show the EditText, no bleed through happens. If you are having issues, you need to post your project just like I did and as @klaus requested so others can reproduce your issue.

Thank you for this sample. I will run it and study it.

UPDATE: I found one problem - buried in the code, after initializing cvsLayer to p3, I see there is code that undoes that: cvsLayer.Initialize(Activity). So that is why it was writing to the Activity view instead of the panel. But using your code as a model, I can get it to work except that all my graphics are magnified like 5 or 10 times. What would cause the same code to magnify the graphics when the canvas is inititalized to a panel rather than Activity?
 
Last edited:
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
So now the question is, if I point my canvas to "Activity" instead of a panel, how do I hide that activity graphics when my EditText is showing. To see what I mean, change this: cv1.Initialize(Panel1) to this: cv1.Initialize(Activity)

I can't live with the screwy magnification that I am getting from writing my graphics to the panel, even though your panel does not distort your circle. I don't know why my scaling is so out of whack when I do the same thing as you - send the canvas drawings to a panel instead of Activity.[/QUOTE]
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Since Activity does not have a (public) method to hide a view and Canvas does not have a means to hide it, attaching the Canvas to the Activity does not seem to give you a means of changing the visibility of the canvas (that I'm aware of. Not an B4A expert). I've created another Panel (manually, without designer) and Canvas, just as you did in Post #4. I still see no distortion, nor any bleed through (even used an Alpha channel on the fill color for the Canvas).

Phone: the original Moto X, running Android 5.1
B4A: 8.00
JDK: 1.8.0u161
Platform: Android-27
 

Attachments

  • CanvasTest2.zip
    9.5 KB · Views: 170
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Yes, I understand what you are saying. And it makes no sense to me why I am seeing such a scaling/magnification effect when writing the canvas to the panel. Yous is fine, but mine is not. I have wasted lots of time time with this today - perhaps tomorrow will bring new light. Thank you for your help. You helped me find one big problem. Yet, so far, my original "problem" is still the best solution. Crazy stuff.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Yous is fine, but mine is not.

If you would upload a sample application that still shows this distortion, I'll gladly run it and see what it does on my end.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
The glitch fairies are out in force and trying to be mean. I pulled up a test program that I had made and modified it with the same sort of panel modifications that I did earlier. The test program worked - no magnification. A couple of instructions were put in a different order, but I wouldn't imagine that should make a difference in scaling (??). Yet the test program displayed my graphics just as expected (with no magnification). So I then took those same instructions, in the same order, and put them into my original program. The graphics are normal now and not magnified. What is the difference? Besides a few instructions being in different order, nothing (except for the passage of time). So now things look okay and I will proceed until the glitch fairies catch up with me again. Sometimes things just aren't supposed to work until it's time for them to work. I've seen it repeatedly in my life. But that doesn't help me understand or predict it. Thanks Oliver et al for bearing with me. I'm still scratching my head over this.
 
Upvote 0
Top