安卓多点触控?
作为一名开发人员,我倾向于先编程,然后再研究。我试图实现一个可以处理多个用户输入的屏幕。基本上映射的不仅仅是一根手指。我尝试了两件事......
我有一个实现 OnTouchListener 的 Activity 类。这里我有两个单独的子视图,它们将 Activity 添加为它们的 ontouch 监听器。然后我有一个打印行,打印出 event.getPointerCount() 并打印出每个指针的位置。
将其下载到手机并进行测试。我注意到指针永远不会超过两个。我什至注意到,如果一根手指放在一个子视图上,另一根手指放在另一个子视图上,则事件只会到达第一个子组件。接下来,我尝试在每个子组件上放置单独的侦听器,看看这是否有效,但其行为相同。
因此,在处理用户触摸屏幕的输入时,Android 似乎只支持总共两个用户输入。
这是真的吗?从测试和研究来看,情况确实如此。
有没有人遇到过这个限制。有什么巧妙的解决方法吗?
感谢您的时间和回复。
dk
As a developer, I tend to program first then research later. I was trying to implement a screen that would handle multiple user inputs. Basically map more than just one finger. I tried two things..
I had an Activity class that implemented OnTouchListener. Here I had two separate child views that added the Activity as their ontouch listeners. And then I had a print line that printed out the event.getPointerCount() and printed out the location of each of the pointers..
Downloaded it to the phone and tested it. I noticed that the pointers never grew greater than two. I even noticed if one finger was on one child and another finger on the other child view that the events only made it to the first child component. Next I tried to put separate listeners on each of the child components to see if that would work but it acted the same.
So, it seems that the android only supports a total of two user inputs when dealing with inputs from the user touching the screen.
Is this true? It seems from testing and research that this is the case.
Has anyone ran into this limitation. Any clever work arounds?
Thanks for you time and responses.
dk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
支持的触摸点数量取决于设备。在所有当前可用的 Android 版本中,
MotionEvent
都会发送到单个目标视图并描述所有当前活动触摸点的状态。目标视图由第一个MotionEvent.ACTION_DOWN
事件发生的位置确定。请参阅帖子 了解多点触控 Android 开发人员博客,快速概述如何在 Android 上处理多点触控事件。
The number of touch points supported is dependent on the device. In all currently available versions of Android
MotionEvent
s are sent to a single target view and describe the state of all currently active touch points. The target view is determined by where the firstMotionEvent.ACTION_DOWN
event occurs.See the post Making Sense of Multitouch on the Android Developers blog for a quick overview of working with multitouch events on Android.
我编写了一个非常简单的应用程序来测试我的 HTC Incredible 手机上的多点触摸。我的行为与我的想法非常相似,并且与 adamp 给出的 URL 非常相似。我的结果是手机只能处理两个手指输入。我有一个盒子,每个盒子都有自己的 OnTouchListener。当我单击每个框时,我会打印每个框的文本。单击每个获取触摸事件,但用食指单击屏幕上的任意位置,我得到两个指针。来自 MotionEvent event.getPointerCount 方法。第二根手指落在哪里并不重要。可能位于接收第一个手指按下事件的原始视图之外。无论如何,如果您想自己尝试一下,这里是代码。
我有整个项目的 7z,但我认为我无法附加它。
所以,这里是主要的 Activity 和布局的 xml。
布局:
祝你好运,如果你尝试一下,请告诉我你是否得到了三个指针!打印报表。我想知道什么手机支持它。
谢谢,
dk
I wrote a very simple application to test multiple touch on my HTC Incredible phone. I behave pretty much like I thought and pretty much like the URL given by adamp. My results is that the phone could only handle two finger inputs. I have for box that each has its own OnTouchListener. When I click each box I print out a text for each. Clicking on each get touch events but with my index finger I clicked anywhere on the screen I got two pointers. From the MotionEvent event.getPointerCount method. Did not matter where the second finger landed. Could have been outside of the original view that received the first finger down event. Anyways here is the code if you like to try it yourself.
I have a 7z of the entire project but I do not think I can attach it.
So, here is the main activity and the xml for the layout.
Layout:
Good luck, and if you try it let me know if you get the GOT THREE POINTERS!! print statements. I wonder what phones supports it.
thanks,
dk
我编辑了@dakira 答案。这是我的示例代码:
这是 JAVA 代码:
希望这能解决很多人的问题:)
I edited @dakira answer. Here is the my sample code:
Here is JAVA code:
Hope this will solve many persons problem :)