分割运动事件 - 同时接受多个视图的输入
我正在尝试使分割触摸事件正常工作,这意味着能够在多个视图中单独检测触摸输入。
这是添加到 honeycomb 中的一项功能,可以使用兼容性库向后移植。 这里有更多信息: http://developer.android.com/sdk/android-3.0 .html ->向下滚动到“拆分触摸事件”
它基本上说: 以前,只有一个视图可以同时接受触摸事件。 Android 3.0 添加了对跨视图甚至窗口拆分触摸事件的支持,因此不同的视图可以同时接受触摸事件。 当应用程序面向 Android 3.0 时,默认启用拆分触摸事件。也就是说,当应用程序将 android:minSdkVersion 或 android:targetSdkVersion 属性的值设置为“11”时。
这是我用来测试它的示例项目: https://sites.google.com/site/droidbean/hologramlwp/downloadmodels/attachments/SplitMotionTest.rar?attredirects=0&d=1
在项目中有2个图像视图,触摸顶部视图生成带有“pointer”标签的 Log.e 事件,而底部视图生成“pointer2”,但正如您所看到的,触摸顶部视图,然后触摸第二个视图单独的手指(两者都触摸单独的视图)仅产生姜饼中第一个视图的消息。
如果同一个项目在 honeycomb 上运行,则它可以正常工作,并且两个视图都会生成各自的“指针”日志条目。
所以我的问题是,如何在运行姜饼或任何其他较低 Android 版本的手机上获得相同的效果?
I'm trying to get split touch events working, this means being able to detect touch input separately in multiple views.
It was a feature added to honeycomb and can be backported using the compatibility library.
There is more info here: http://developer.android.com/sdk/android-3.0.html
->Scroll down to "split touch events"
It basically says:
Previously, only a single view could accept touch events at one time. Android 3.0 adds support for splitting touch events across views and even windows, so different views can accept simultaneous touch events.
Split touch events is enabled by default when an application targets Android 3.0. That is, when the application has set either the android:minSdkVersion or android:targetSdkVersion attribute's value to "11".
Here is a sample project I am using to test it:
https://sites.google.com/site/droidbean/hologramlwp/downloadmodels/attachments/SplitMotionTest.rar?attredirects=0&d=1
In the project there are 2 imageviews, touching the top one produces Log.e events with a tag of 'pointer' while the bottom view produces 'pointer2' but as you can see touching the top view and then the 2nd with a separate finger (both are touching separate views) produces only messages from the first view in gingerbread.
If the same project is run on honeycomb, it works correctly and both views produce their respective 'pointer' log entries.
So my question would be, how do I get this same effect on a phone running gingerbread or any other lower android version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 Gingerbread 不支持拆分触摸事件,因此一种解决方案是在两个视图上创建覆盖。例如,在 xml 中的其他视图之后或在覆盖这两个视图的代码中添加一个空的relativelayout,我们将其称为覆盖。设置覆盖层的 OnTouchListener 并以编程方式确定事件发生的视图 (x,y)。然后将该事件发送到确定的视图的 onTouchEvent。
这不是很友好,这就是他们修复它的原因。
例子:
Since Gingerbread doesn't support splitting touch events, one solution would be to create an overlay over the two views. e.g. add an empty RelativeLayout after the other views in the xml or in code that covers the two views, let's call it the overlay. Set the overlay's OnTouchListener and programmatically determine which view the event occured (x,y). Then send the event through to the determined view's onTouchEvent.
This is not very friendly, that's why they fixed it.
Example: