java 触屏位置_java – 如何在android屏幕上检测触摸位置?

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

public boolean onTouchEvent(MotionEvent event){

float x_forOnTouch = event.getX();

float y_forOnTouch = event.getY();

getX()和getY()函数返回的确切内容是什么?是否返回像素值?当手指触摸屏幕位置时,它可能会触摸许多像素.那么函数究竟返回了什么?

再次,让我们假设在我用手指触摸的区域中,屏幕上有多个像素,如下所示:

假设我需要单击并拖动像素1处的点,但是我的手指触摸的区域覆盖像素1和2.如何准确检测哪个像素被点击,以便我可以单击并拖动像素1或2需要它?

解决方法:

我想这些值是blob或触摸区域的中心.请记住,它可以是像鼠标或手写笔一样的工具,因此该区域将更加精确.它具有触摸手指的假定区域的方法和常量.

该链接有很多关于这个问题的方法,我不会复制和粘贴,因为它有很多文档,所以我认为你需要阅读它.

其中一些:

getPressure()

的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,touchscreen,motionevent

来源: https://codeday.me/bug/20190520/1141566.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值