Panel is 'touch-through'

JesseW

Active Member
Licensed User
Longtime User
I have an issue. I've developed a very custom dialog which I have created on a panel in the designer. Then at startup, I programmatically create a panel the size of the Activity using the FillParent option, which is specified with a width and height value of -1, and set its color to ARGB(180, 1, 1, 1) which is a dark transparent black, which dims whats behind it, then load the custom dialog layout. pnlInput is of course Dim'd in Sub Globals.

Here is my init code:

B4X:
   pnlInput.Initialize("")
   activity.AddView(pnlInput, 0, 0, -1, -1)
   pnlInput.Visible = False
   pnlInput.LoadLayout("input")
   pnlInput.Color = Colors.ARGB(180, 1, 1, 1)
   Panel1.Top = Activity.Height - Panel1.Height - 20dip

That simply sets up what I've described, hides it, then set's the dialogs vertical position. Then when its needed, I call it like this:

B4X:
   pnlInput.Visible = True
   pnlInput.BringToFront

and I've attached a screenshot below. Also note that when the translucent panel is called to front and made visible, it overlays a scrollview with a series of labels.

Problem is, in the emulator anyway, you can scroll what's behind/underneath the translucent panel, by grabbing it on either side of the gray dialog panel and moving up and down. I even tried adding pnlInput to the activity as the very last step, and also tried using Activity.Width and Activity.Height instead of using FillParent, but it didn't change anything... Even disabling the scrollview behind the panel didn't stop it from scrolling.

This really threw me for a loop. I didn't think even a completely transparent panel would let touch events through. This was the way I was going to make the 'dialog' modal, by allowing you to see what's behind the panel, but not allowing you to touch. But as it turns out, if a user wants to change the day displayed in the dialog, they can without exiting the dialog. And that's not a bad thing in this particular app. So all is not lost.

But this is too weird! Can anyone tell me if I've done something wrong? Or if I've left out something? I'm thinking that views behind/underneath a panel, even a transparent one, should never be able to be clicked, dragged, scrolled or otherwise manipulated.

Help??

Jesse
 

Attachments

  • recap.jpg
    recap.jpg
    69 KB · Views: 322
Last edited:

JesseW

Active Member
Licensed User
Longtime User
You have to set the transparent panel (on the designer) to FALSE and add an empty "Panel_Click" event to catch it

But I'm creating the panel programmatically, not in the designer, and I don't want to set its transparency to false. That's the point, to make it look like a dialog. I can catch it's _Click event, but that can't be consumed like a keystroke even can be, so that'd be of not use here...

Edit: as expected, creating pnlInput_Click event didn't consume the event. That didn't work. Setting Enable=False would disable the dialog panel and all the views I've placed on the dialog panel - NJDude, I appreciate your reply :)
 
Last edited:
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
It will look like a dialog, I've done the same thing.

You will have to add: pnlInput.Enabled = False

Tried pnlInput.Enabled = False and that didn't change anything. Completely unexpected. It didn't disable the dialog panel or any of the views on it, but it also didn't keep the scrollview from scrolling either.

I'm tempted to send you the project so you can see what I'm talking about... I sent you a PM by the way...

Jesse
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Check this sample.

Thanks for this helpful little sample, NJDude.

Every day I am learning something new about B4A. This really is THE Ultimate RAD Tool for Android!
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
You should catch the Panel Click event to consume the event.
B4X:
Sub pnlInput_Click

End Sub

Thanks Erel for the input, but doing that didn't change anything: the scrollview behind the panel was still scrollable...
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Are you running your app in the emulator? In that case the scrollview will still catch the mousewheel events but no mouseclicks. Should work properly on a real device.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
I think you also shoul set the focus to your pnlInput or one of the views on it.

B4X:
pnlInput.RequestFocus

That worked for me!
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
You should catch the Panel Click event to consume the event.
B4X:
Sub pnlInput_Click

End Sub

My bad... NJDude pointed out that I don't initialize the panel with the event name, so the event wont fire and consume the touch. I will look into this this afternoon.
 
Upvote 0

JesseW

Active Member
Licensed User
Longtime User
THAT DID IT!!!

Who would have thought? :sign0161:

Thanks NJDude for holding my hand through this and showing me the way; much respect! :sign0188:

And thanks to Erel for confirming when I was disbelieving...
 
Upvote 0
Top