【问题标题】:How can I get coordinates of two points simultaneously touched on screen in Android?如何在Android的屏幕上同时获取两个点的坐标?
【发布时间】:2012-09-10 23:28:52
【问题描述】:

我想知道当屏幕同时触摸到屏幕上的点时,是否有可能获得两组正确的坐标点。 如果是,那么如何使用它。谷歌搜索,但没有得到任何满意的结果。请帮忙?

【问题讨论】:

  • 好吧,您可以保存在最后 ​​X 毫秒内发生的所有触摸事件,并在每个新的触摸事件中检查最后一次触摸是否在 Y 秒的阈值内发生。如果此条件适用,则它们“同时”发生。
  • 我没明白!!你能澄清一下吗!
  • onTouch:saveTimeStamp 和坐标(这可能是您的第一次触摸) onAnotherTouch:saveTimeStamp 并检查它是否几乎与第一。你知道我的意思吗?我认为您的手指不会同时触碰屏幕,因此您还希望将事件识别为“同时发生”,如果这些事件发生在彼此之后不久。
  • 这是个好主意,我想我会试试的..thanx
  • 更简单:在 onTouch 事件中使用 MotionEvent.getHistoricalEventTime(pos) 检查最后一次触摸的时间差!刚刚找到它here希望这有效^.-

标签: android touch-event ontouchlistener


【解决方案1】:

使用以下两种方法代替getX和getY:

public final float getX (int pointerIndex)
        Since: API Level 5

        Returns the X coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.


public final float getY (int pointerIndex)
        Since: API Level 5

        Returns the Y coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise.
        Parameters
        pointerIndex    Raw index of pointer to retrieve. Value may be from 0 (the first pointer that is down) to getPointerCount()-1.

【讨论】:

猜你喜欢
  • 2016-05-29
  • 1970-01-01
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-24
  • 2015-10-26
  • 2020-04-13
相关资源
最近更新 更多