曼波鱼Sunfish 2014-07-10 03:28 采纳率: 0%
浏览 5267

Android 传感器中,压力传感器(感应手指的触摸压力,非气压传感器)的实现问题

关于Android是否可以获取触摸压力,SDK中有这样一段话支持这个观点:
“For example, when the user first touches the screen, the system delivers a touch event to the appropriate View with the action code ACTION_DOWN and a set of axis values that include the X and Y coordinates of the touch and information about the pressure, size and orientation of the contact area.”
其中
1、MotionEvent.getPressure():“Returns the current pressure of this event for the given pointer index”
2、MotionEvent.getSize():“Returns a scaled value of the approximate size for the given pointer index”
受有道云笔记手写功能启发,请问有压力传感器开发经验的同行具体实现中主要用哪个函数?该怎么用?精确率如何?
参考:http://docs.huihoo.com/android/4.2/reference/android/view/MotionEvent.html#AXIS_PRESSURE

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-02 06:34
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    在Android的MotionEvent类中,getPressure()方法用于获取当前事件的压力值。它接受一个指针索引作为参数,返回该指针所对应的事件的压力值。

    以下是一个简单的例子,演示了如何使用getPressure()方法:

    MotionEvent motionEvent = new MotionEvent();
    motionEvent.setPointerId(0, 0); // 设置第一个指针为0号
    int pressure = motionEvent.getPressure(); // 获取压力值
    

    需要注意的是,由于设备和应用程序之间的差异,实际的精度可能会有所不同。因此,在使用这些信息时,应该进行适当的误差处理。

    至于具体的实现细节,这通常取决于传感器的具体类型以及设备的支持情况。一般来说,大多数现代智能手机都支持压力传感器,并且可以通过API来访问它们。然而,不同类型的传感器可能有不同的API,因此在具体实现中,可能需要根据实际情况来进行调整。

    评论

报告相同问题?