获取正在接收所有触摸事件的视图 [英] Getting the View that is receiving all the touch events

查看:145
本文介绍了获取正在接收所有触摸事件的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统覆盖层,首先位于活动 Windows 之上。唯一的问题是,当用户将他/她放在屏幕上时,它只能检测到 MotionEvents (它不能跟踪手指的移动或检测手指何时被抬起)。作为一个可能的解决方案,我实现了第二个视图(我称之为跟踪视图),它能够处理所有的触摸事件,但保持隐藏,直到系统覆盖层检测到所需位置的触摸;在这种情况下,它将提供跟踪视图。只有问题是,跟踪视图才会开始检测触摸事件,直到用户将他/她的手指放回屏幕上。因此,为了解决这个问题,我想拦截获取触摸事件的视图(这是系统覆盖下的视图),并将所有触摸事件转发到跟踪视图进行处理。

I have a system overlay that sits above all Activities and Windows. 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). 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.

推荐答案

你不能做你正在问的事情。输入系统非常小心限制什么窗口可以收到什么事件;它是故意不像其他系统,如Microsoft Windows,您可以参与低级别的事件调度,并看到所有事情。唯一允许的是:

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:


  • 可以接收所有事件的窗口,或者任何窗口后面的窗口(不允许这些事件)被窗户后面收到)。这被称为触摸模态。

  • 可以在其矩形内接收所有事件的窗口,而不让其转到其后面的窗口,但是矩形之外的事件可以转到它后面的适当的窗口,而不被它看到。这被称为不触摸模态。

  • 不触摸模态的变体,允许它被告知只有在其窗口之外发生的down事件。然而,它不会再收到任何其他事件,并作为特殊操作代码发送: http: //developer.android.com/reference/android/view/MotionEvent.html#ACTION_OUTSIDE

  • 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

另一个核心规则事件调度到Windows的是,一旦窗口被选为触摸事件的目标,它将继续接收事件流,直到最后。传统上在Android中,这将适用于触摸手势的所有其他手指(它接收所有手指,无论它们出现在哪里,直到最后一个手指上升)。更新版本的平台允许您修改此行为以获得多点触摸: http ://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SPLIT_TOUCH

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.

这篇关于获取正在接收所有触摸事件的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆