Getting the View that is receiving all the touch events

后端 未结 1 1506
孤街浪徒
孤街浪徒 2021-01-05 08:50

I have a system overlay that sits above all Activities and Windows. The only problem is that it can only detect MotionEvents when a us

1条回答
  •  迷失自我
    2021-01-05 09:19

    You can't do exactly what you are asking. The input system is very careful to restrict what windows can receive what events; it is deliberately not like other systems such as Microsoft Windows where you can get involved in the low-level event dispatching and see everything going on. The only things allowed are:

    • A window that can receive all events that would go to it or any windows behind it (without allowing those events to be received by the windows behind it). This is called "touch modal".
    • A window that can receive all events within its rectangle without letting those go to windows behind it, but events outside of the rectangle are allowed to go to the appropriate window behind it without being seen by it. This is called "not touch modal".
    • A variation on "not touch modal" that allows it to be told about only the down event that happens outside of its window. It will not receive any other further events, however, and is delivered as a special action code: http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_OUTSIDE

    A further core rule of event dispatching to windows is that once a window is selected as the target of the touch event, it will continue to receive the event stream until the final up. Traditionally in Android this would apply to all further fingers of the touch gesture (it receives all fingers, no matter where they appear, until the last finger goes up). More recent versions of the platform allow you to modify this behavior to be multi-touch aware: http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SPLIT_TOUCH

    So those are the tools you have in your tool box. You can build the things that are possible with them, but this is not intended to allow you to do any possible kind of interaction with the event system, so there are going to be limits.

    0 讨论(0)
提交回复
热议问题