java - 如何检测 android 屏幕上的触摸位置?

标签 java android touchscreen motionevent

我们可以使用以下函数获取触摸位置在屏幕上的坐标:

public boolean onTouchEvent(MotionEvent event){
    float x_forOnTouch = event.getX();
    float y_forOnTouch = event.getY();  

getX()getY() 函数究竟返回了什么?它是否返回像素值?当手指触摸到一个屏幕位置时,它可能会触摸到一些像素。那么这个函数到底返回了什么?

再次,假设在我用手指触摸的区域,屏幕上有多个像素点,如下图:
enter image description here

假设我需要点击并拖动像素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/

相关文章:

java - 无法找到其他包中声明的 Activity

java - 复制文件的文件创建日期java nio

java - 使用 XSD 中的元素 "anyAttribute"和 "any"将 XML 编码为 Java

android - 使用 authToken 对 Google Talk(XMPP、Smack)进行身份验证

触摸屏上水平滑动的 jQuery 监听器?

touchscreen - 如何在 gnome 3.14 中禁用边缘触摸屏手势

linux - Linux下判断设备是否为触摸屏设备

java - 使用准备好的语句的变量列名

java - java中BST中给定元素的递归中序后继

java - 如何定期更新 Firebase 实时数据库的位置?