安卓:多点触摸和TYPE_SYSTEM_OVERLAY [英] Android : Multi touch and TYPE_SYSTEM_OVERLAY
问题描述
我试图让一个系统的覆盖视图多点触摸事件,但我只接受 MotionEvent.ACTION_OUTSIDE
事件。
I am trying to get multiple touch events on a system overlay view, but am only receiving the MotionEvent.ACTION_OUTSIDE
event.
有没有一个系统的覆盖越来越多点触摸事件的任何可能的方式?
Is there any possible way of getting multiple touch events on a system overlay?
任何实例或链接将是非常有益的。
Any examples or links would be very helpful.
推荐答案
要创建一个覆盖视图,设置当的LayoutParams
您需要设置类型为 TYPE_SYSTEM_OVERLAY
和使用标志 FLAG_WATCH_OUTSIDE_TOUCH
。这presents一个问题,因为随着Android的文件规定:
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:
您将不会收到完整的向下/移动/向上的姿态,先放下,作为唯一的位置的 ACTION_OUTSIDE
。
you will not receive the full down/move/up gesture, only the location of the first down as an
ACTION_OUTSIDE
.
为了获得你需要使用 TYPE_SYSTEM_ALERT
式触摸事件的全阵列,而这将导致覆盖接管屏幕,并停止与其他元素的相互作用。解决的办法是同时使用 TYPE_SYSTEM_OVERLAY
和 TYPE_SYSTEM_ALERT
键,通过改变的LayoutParams
需要。
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.
这是通过完成:
- 观看了
ACTION_OUTSIDE
的议案事件。 - 在遇到这样的情况,检验它是否覆盖范围内发生。
- 如果它没有,切换
的LayoutParams
键入TYPE_SYSTEM_ALERT
- 一旦与覆盖层的交互完成,切换回
TYPE_SYSTEM_OVERLAY
- 重复
- Watch for the
ACTION_OUTSIDE
motion event. - When it occurs, test if it occured within the overlay.
- If it did, switch the
LayoutParams
type toTYPE_SYSTEM_ALERT
- Once the interaction with the overlay is complete, switch back to
TYPE_SYSTEM_OVERLAY
- Repeat
有一件事要记住的是, ACTION_OUTSIDE
的议案事件总是传递到屏幕上的其他元素。因此,例如,如果叠加是在按钮的顶部,该按钮也将获得的运动事件,也没有办法阻止它
The one thing to keep in mind is that the ACTION_OUTSIDE
motion event is always passed on to the rest of the elements on the screen. So, for example, if the overlay is on top of a button, that button will also receive the motion event and there is no way to stop it.
另外,还要确保你的 SYSTEM_ALERT_WINDOW
许可添加到的mainifest文件。
Also make sure you add the SYSTEM_ALERT_WINDOW
permission to the mainifest file.
我已经发布了完整的解决方案在这里:
http://www.jawsware.mobi/$c$c_OverlayView/ (修订版) 的
I've posted the complete solution here:
http://www.jawsware.mobi/code_OverlayView/ (UPDATED)
这包括所有的源$ C $ c和一个链接,下载整个示例项目。
It includes all the source code and a link to download the entire example project.
更新的Android 4.0 - 2013年1月3日
要创建一个覆盖视图,设置时的LayoutParams的不要类型设置为 TYPE_SYSTEM_OVERLAY
。
To create an overlay view, when setting up the LayoutParams DON'T set the type to TYPE_SYSTEM_OVERLAY
.
相反,它设置为 TYPE_PHONE
。
使用以下标志:
FLAG_NOT_TOUCH_MODAL
FLAG_WATCH_OUTSIDE_TOUCH
FLAG_NOT_TOUCH_MODAL
<<我发现这个是非常重要的。没有它,焦点是考虑到叠加和软键(家庭,菜单等)presses不传递到下面的活性。
FLAG_NOT_TOUCH_MODAL
<< I found this one to be quite important. Without it, focus is given to the overlay and soft-key (home, menu, etc.) presses are not passed to the activity below.
此外,previous链接(上图)已被更新,以反映此更新。的
Also, the previous link (above) has been updated to reflect this update.
这篇关于安卓:多点触摸和TYPE_SYSTEM_OVERLAY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!