Android Question How can I pass click/touch events through a transparent panel

crimson ghost

Member
Licensed User
Longtime User
I did a transparent panel overlaying another panel with buttons and stuff. I did this so I could process touch events and this part works fine. However, clicking on anything on the underlying panel does nothing. The click routines are not called. However, I checked and click events register on the transparent panel. I return false from everything so nothing is consumed if I understand that correctly (although it appears returning true or false makes no difference and, if a boolean is to be returned, why are the subs defined without an "as boolean"?). Summary: transparent panel overlayed on a panel with stuff on it. Touch and click events register on the transparent panel but nothing registers on the underlying panel unless I do nothing with the transparent panel (no touch or click event processing which sort of makes it pointless to have it). How do I get this to work? How do you get things to pass through events to underlying views?
 

DonManfred

Expert
Licensed User
Longtime User
Remove the touch event sub for the transparent panel.
If you handle the touch the event is eating the touch
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
A (not so long) way to handle it is generating yourself the events of the views under the panel when needed

For instance, assume you want to handle "CLick" events to the views under the panel (and you know where these views are)

>You receive an ACTION_DOWN event on your transparent panel (which is not handled by any of the views in it)
>According to its coordinates (relative to he transparent panel), you decide wether it belongs to some view under it or not
> If so, you keep: a reference to this view (let's name it recordedView), the transformed coordinates [touch.X - yourImageview.X , touch.Y - youImageView.Y ] and a time stamp. All these vars defined in Globals for later use
> Wait until you receive an ACTION_UP event in the transparent panel.
> Now check if the (transformed) coordinates still belong to the imageview, and if the ellapsed time is small enough to be considered a "Click"
> If so, call yourImageview_Click( recordedView as Object )
> If not, do nothing.​

Can't code it right now, but should be quite easy :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
you put a transparent panel to be able to handle touch event on it but not when you click on buttons that are on a panel below.
don't understand why you need another panel.

the buttons are already on a panel, just remove the above transparent panel and handle the touch event on the panel that holds the buttons and the click events will work.
if you want to be able to slide on buttons and handle the touch event then you will need to do what jordiCP wrote above but the touch down/up has a different filling then button click.

why exactly are you doing it like this? maybe there is another solution. you could use a scroll view that holds buttons and like this you could hand scoll and click on buttons.
 
Upvote 0

crimson ghost

Member
Licensed User
Longtime User
Jordicp, thanks for the long reply, but I already know that. I refer to that as the brute force way. Ilan, see previous remarks about removing the transparent panel. Let me rephrase the question. How can i overlay a transparent panel that processes touch and click events yet will pass them through to an underlying panel. Is this possible in some easy way?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Ilan, see previous remarks about removing the transparent panel

btw. you don't explain what you would like to do and why you put a transparent panel to register touches on it. and instead of sending me to nowhere just explain why are you doing it like this if you would like to get help or suggestion to another way to solve your problem.
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
What you would have to do on the overlay code is make the decisions that the OS would make. Basically, you get the touch location and press/release action. You then determine if the touch is within the confines of a view that could service the touch (is it between the left and right and top and bottom of a view). Then you decode the action. Was is a touch or release. Then you call the sub that would have been called if the transparent overlay wasn't there. How much decoding and sub mapping will depend on what you want to be active at that time and what makes sense. You probably don't need to map a label but would map a button.
 
Upvote 0
Top