简体   繁体   English

在 Android 上,当第一根手指从屏幕上松开时,如何判断第二根手指的位置,该手指没有移动但正在触摸屏幕

[英]On Android, how can I tell the location of a second finger that isn't moving but is touching the screen when the first finger releases from the screen

I'm using Java in Android.我在 Android 中使用 Java。 I'm having trouble explaining this so I'll try again.我无法解释这一点,所以我会再试一次。

1 finger touches the screen and I use the event.getX()/Y() to get its cords.一根手指触摸屏幕,我使用 event.getX()/Y() 来获取它的绳索。

Another finger touches the screen and I'm still getting the X/Y of the first finger.另一根手指触摸屏幕,我仍然得到第一根手指的 X/Y。

Now the first finger is removed from the screen, however the second finger has yet to move and so it doesn't trigger the ACTION_MOVE and I can't get the event.getX()/Y() yet.现在第一根手指已从屏幕上移除,但第二根手指尚未移动,因此它不会触发 ACTION_MOVE,我还无法获取 event.getX()/Y()。

I want to know, how can I make it so even if the second finger hasn't moved yet how I can get it's X and Y as soon as the first finger releases from the screen.我想知道,即使第二根手指还没有移动,我怎么能做到这一点,一旦第一根手指从屏幕上松开,我怎么能得到它的 X 和 Y。 As of right now I'm having my character move towards the finger, and I have found it is quite common for this to happen and when it does the character continues to move towards the location of where the first finger left off until you move your finger slightly.截至目前,我正在让我的角色向手指移动,我发现这种情况很常见,当它发生时,角色会继续向第一根手指离开的位置移动,直到你移动你的手指手指轻轻。 It happens enough to make it a problem, especially for what I'm trying to do.这足以使它成为一个问题,尤其是对于我正在尝试做的事情。

I had the same problem when I was retrieving the position touched like this:我在检索 position 时遇到了同样的问题:

CGPoint touchLocation = CGPoint.make(event.getX(), event.getY();

Fixed it by using:通过使用修复它:

CGPoint touchLocation = CGPoint.make(event.getX(event.getPointerCount()-1), event.getY(event.getPointerCount()-1));

MotionEvent has more details for the second finger. MotionEvent 有更多关于第二根手指的细节。 Do review the documentation.请查看文档。

look at the values in event.getX(1) and event.getY(1) methods.查看 event.getX(1) 和 event.getY(1) 方法中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android touchlistener中同时检测到触摸屏幕上的次要手指? - how to detect the secondary finger on touching the screen not at same time in android touchlistener? 让最后一根手指触摸屏幕 - Getting the last finger touching the screen Android:当另一个手指已经触摸屏幕时,是否可以处理点击? - Android: Is it possible to handle a click while another finger is already touching the screen? OnTouchEvent:我想在用另一个手指在屏幕上移动时识别触摸 - OnTouchEvent: I want to recognize touches while moving with an another finger on the screen 每当用户的手指不触摸屏幕时,我都想让游戏暂停 - I want to make my game pause whenever the users finger is not touching the screen 我可以以编程方式在Android屏幕中扣除拇指按下或手指按下吗? - Can i deduct that either thumb pressed or finger pressed in android screen programmatically? android通过手指触摸屏幕上删除线 - android remove line by finger touch on screen 手指在屏幕上滑动的灵敏度 - The sensitivity of the finger swipe on the screen 检测手指何时离开屏幕并更新指针 - detect when a finger leaves the screen and update pointers 按下按钮时无需从屏幕上松开手指 - Press buttons without release finger from screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM