Android Question Hide a canvas or make it invisible

Discussion in 'Android Questions' started by aedwall, Apr 16, 2018.

  1. aedwall

    aedwall Active Member Licensed 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.
     
  2. klaus

    klaus Expert Licensed User

    A Canvas is not a view, it's a drawing tool and has a target view which you set in Canvas.Initialize(TagetView) method.
    You should set the Visible property of this TagetView to False.
     
  3. aedwall

    aedwall Active Member Licensed 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.
     
  4. aedwall

    aedwall Active Member Licensed 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?
     
  5. klaus

    klaus Expert Licensed 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
     
  6. MarkusR

    MarkusR Well-Known Member Licensed User

    how about filling the "canvas" with transparent?
     
  7. aedwall

    aedwall Active Member Licensed User

     
  8. aedwall

    aedwall Active Member Licensed User

    Not sure how to do that - I have to look it up.
     
  9. MarkusR

    MarkusR Well-Known Member Licensed User

    at least there is a Color Value but i did not testet it.
    Code:
    Colors.Transparent
    Canvas1.DrawColor(
    Colors.Transparent)
     
  10. aedwall

    aedwall Active Member Licensed 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)
     
  11. OliverA

    OliverA Well-Known Member Licensed 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.
     

    Attached Files:

  12. aedwall

    aedwall Active Member Licensed User

    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: Apr 17, 2018
  13. aedwall

    aedwall Active Member Licensed 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]
     
  14. OliverA

    OliverA Well-Known Member Licensed 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
     

    Attached Files:

  15. aedwall

    aedwall Active Member Licensed 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.
     
  16. OliverA

    OliverA Well-Known Member Licensed User

    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.
     
  17. aedwall

    aedwall Active Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice