简体   繁体   English

获取正在接收所有触摸事件的视图

[英]Getting the View that is receiving all the touch events

I have a system overlay that sits above all Activities and Windows .我有一个位于所有ActivitiesWindows之上的系统覆盖。 The only problem is that it can only detect MotionEvents when a user places his/her down on the screen (it can't track the finger's movements or detects when the finger is lifted).唯一的问题是它只能在用户将他/她放在屏幕上时检测到MotionEvents (它无法跟踪手指的运动或检测手指何时抬起)。 As a possible solution, I've implemented a second view (I'll call it the tracking view) that is able to handle all the touch events, but stays hidden until a touch in the desired location is detected by the system overlay;作为一种可能的解决方案,我实现了第二个视图(我将其称为跟踪视图),它能够处理所有触摸事件,但在系统覆盖检测到所需位置的触摸之前一直处于隐藏状态; in that event, it will bring up the tracking view.在这种情况下,它将调出跟踪视图。 Only problem is, that the tracking view doesn't start detecting touch events until the user places his/her finger back down on the screen.唯一的问题是,在用户将他/她的手指放回屏幕上之前,跟踪视图不会开始检测触摸事件。 So to resolve this, I want to intercept the view that's getting the touch events (which is the view beneath the system overlay) and forward all its touch events to the tracking view to process.所以为了解决这个问题,我想拦截获取触摸事件的视图(这是系统覆盖下方的视图)并将其所有触摸事件转发到跟踪视图进行处理。

Does anyone know how I can get the view that's receiving all the touch events and redirect all the touch events it's receiving?有谁知道我如何获得接收所有触摸事件的视图并重定向它接收的所有触摸事件?

This question refers to the examples used in this question .这个问题是指这个问题中使用的例子。

You can't do exactly what you are asking.你不能完全按照你的要求去做。 The input system is very careful to restrict what windows can receive what events;输入系统非常小心地限制了windows可以接收什么事件; 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.它故意不像其他系统,如 Microsoft Windows,您可以参与低级事件调度并查看正在发生的一切。 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). 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. 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. “非触摸模式”的一种变体,允许它仅被告知发生在其 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但是,它不会接收任何其他事件,并作为特殊操作代码提供: 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.对 windows 的事件派发的另一个核心规则是,一旦选择了 window 作为触摸事件的目标,它将继续接收事件 stream 直到最后。 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).传统上,在 Android 中,这将适用于触摸手势的所有其他手指(它接收所有手指,无论它们出现在哪里,直到最后一个手指抬起)。 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该平台的更新版本允许您修改此行为以支持多点触控: 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.您可以使用它们构建可能的东西,但这并不是为了让您与事件系统进行任何可能的交互,因此会有限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM