views:

30

answers:

1

Hi,
I want to have a transparent view, above my application.
I want to do this just knowing the current activity.
I found a way of doing this by adding a new framelayout via the windowManager I m doing this :

public static void AddViewAbove(Activity activity) {
    FrameLayout newLayout = new FrameLayout(activity);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT,
    WindowManager.LayoutParams.TYPE_APPLICATION,
    // if I let WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE   
    // then touchevent are passed to the application behind, but I cant handle touch in
    // my new frameLayout
    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
    PixelFormat.TRANSLUCENT);
    activity.getWindowManager().addView(newLayout , lp);

}

My main problem now is that i can't receive touchevent correctly in my new FrameLayout and in the same time in application behind my view.

Can you help me ??
Thanks a lot,
Have a nice day

Victor

A: 

Haven't tested yet. But the idea is you need to pass-thru the touch event down. Since it is assumed that your top level (and actually top) view handled the event, you might need to set your transparent framelayout to NOT handle the touch event (and other events, if applies).

==Update==

You should inherit the FrameLayout and create your own transparent layout. then instruct it to monitor and by-pass the touch event. Reference

Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point. Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

  1. You will receive the down event here.
  2. The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
  3. For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
  4. If you return true from here, you will not receive any following events: the target view will receive the same event but with the action ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.

==UPDATE==

BTW, you should use your custom framelayout (or other layout that suits you) to "hold" the other child. I suggest you can use that as your root layout.

xandy
Hi,Thanks you for your response, I tried what you suggested but the event is not passing down. If i debug, at each Touch Event (like you mentioned) I m passing false, but the Views behind dont receive anything. Can you help me ?
it should be using ViewGroup.onInterceptTouchEvent instead. I updated the answer
xandy