我们可以使用以下函数获取触摸位置在屏幕上的坐标:
public boolean onTouchEvent(MotionEvent event){
float x_forOnTouch = event.getX();
float y_forOnTouch = event.getY();
getX()
和 getY()
函数究竟返回了什么?它是否返回像素值?当手指触摸到一个屏幕位置时,它可能会触摸到一些像素。那么这个函数到底返回了什么?
再次,假设在我用手指触摸的区域,屏幕上有多个像素点,如下图:
假设我需要点击并拖动像素1处的点,但我手指触摸的区域覆盖了像素1和2。如何准确检测到哪个像素被点击,以便我可以点击并拖动像素1或2 什么时候需要?
最佳答案
嗯,这对你有帮助: http://developer.android.com/reference/android/view/MotionEvent.html
我假设这些值是 Blob 的中心或触摸区域。请记住,它可以是鼠标或手写笔之类的工具,这样区域会更精确。它具有手指触摸区域的方法和常量。
这个链接有很多关于这个问题的方法,我不会复制和粘贴,因为它有很好的文档,所以我认为你需要阅读它。
其中一些:
获取压力()
getSize()
getPointerCount()
getXPrecision()
关于返回值,设备类型部分将提供大量信息。
一些相关的:
The interpretation of the contents of a MotionEvent varies significantly depending on the source class of the device.
On pointing devices with source class SOURCE_CLASS_POINTER such as touch screens, the pointer coordinates specify absolute positions such as view X/Y coordinates. Each complete gesture is represented by a sequence of motion events with actions that describe pointer state transitions and movements.
On joystick devices with source class SOURCE_CLASS_JOYSTICK, the pointer coordinates specify the absolute position of the joystick axes. The joystick axis values are normalized to a range of -1.0 to 1.0
关于java - 如何检测 android 屏幕上的触摸位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18805484/