使用 WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 获取所有 MotionEvent

发布于 2024-11-24 06:58:15 字数 653 浏览 3 评论 0原文

我的问题直接涉及这个问题。该问题的答案展示了如何创建一个 ViewGroup,将其嵌入到 WindowManager 中,并允许 WindowManager 捕获 MotionEvent 通过onTouchEvent(MotionEvent event)WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH 是允许此 ViewGroup 接收 MotionEvent 的标志。然而,根据文档,这个标志

...不会收到完整的向下/移动/向上手势

我想知道是否有解决方法或方法,以便我可以获得所有触摸事件,包括向下、移动和向上。概念验证位于应用Wave Launcher中它使用相同的概念,但能够接收多个 ACTION_OUTSIDE 事件。

My question refers directly to this question. The answer to that question shows how one can create a ViewGroup, embed it inside a WindowManager, and allow the WindowManager to catch MotionEvents through onTouchEvent(MotionEvent event). WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH is the flag that allows this this ViewGroup to receive MotionEvents. However, according to documentation, this flag

...will not receive the full down/move/up gesture

I want to know if there's a work-around or a way so that I can get all touch events including down, move, and up. A proof of concept is in the app Wave Launcher which uses the same concept but is able to receive more than just a single ACTION_OUTSIDE event.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-12-01 06:58:43

我意识到这是一个老问题,但我在尝试完成类似的事情时偶然发现了它。我也发现了这个,希望对某人有帮助: http://www.section465.com/code_OverlayView/

要创建覆盖视图,设置您需要的LayoutParams时
将类型设置为 TYPE_SYSTEM_OVERLAY 并使用该标志
FLAG_WATCH_OUTSIDE_TOUCH。这提出了一个问题,因为
Android 文档指出:“您将不会收到完整的
向下/移动/向上手势,仅将第一个向下的位置作为
ACTION_OUTSIDE。”为了接收完整的触摸事件数组
您需要使用 TYPE_SYSTEM_ALERT 类型,但这会导致
覆盖以接管屏幕并停止与其他人的交互
元素。解决方案是同时使用 TYPE_SYSTEM_OVERLAY 和
TYPE_SYSTEM_ALERT 并通过更改类型在它们之间切换
根据需要设置布局参数。

I realize this is an old question, but I've stumbled across it while trying to accomplish something similar. I've also found this, hopefully it is helpful to someone: http://www.section465.com/code_OverlayView/

To create an overlay view, when setting up the LayoutParams you need
to set the type to TYPE_SYSTEM_OVERLAY and use the flag
FLAG_WATCH_OUTSIDE_TOUCH. This presents a problem because as the
Android documentation states: "you will not receive the full
down/move/up gesture, only the location of the first down as an
ACTION_OUTSIDE." In order to receive the full array of touch events
you need to use the TYPE_SYSTEM_ALERT type, but this causes the
overlay to take over the screen and stop interaction with other
elements. The solution is to use both TYPE_SYSTEM_OVERLAY and
TYPE_SYSTEM_ALERT and switch between them by changing the type of the
LayoutParams as needed.

南巷近海 2024-12-01 06:58:41

不,你不能,这很大程度上是设计使然。

Wave Launcher 不会这样做,它有一个 UI 元素,您可以在其中启动触摸手势,然后与标准一样,甚至分派所有触摸事件都会传递到第一个向下点的窗口,直到最后向上。

No you can not, and that is very much by design.

Wave Launcher doesn't do this, it has a UI element where you start your touch gesture and then as with standard even dispatching all touch events are delivered to the window of the first down point until the final up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文