gpt4 book ai didi

java - getTouchMajor() 不精确 : I can not get real value about the touch area length

转载 作者:行者123 更新时间:2023-12-02 10:22:39 24 4
gpt4 key购买 nike

我想在Android手机上用手指触摸屏幕时显示触摸区域的长度和宽度。尝试了 getTouchMajor() 方法后,它只能为我提供 [55, 99, 123, 187, 219, 250 等] 的离散数字,而不是当触摸区域发生变化时连续变化。

相反,getX()和getY()方法非常敏感,可以提供触摸位置的连续值。但 getTouchMajor() 和 getTouchMinor 无法做到这一点。

@Override
public boolean onTouchEvent(MotionEvent event) {
float touchX = event.getX();
float touchY = event.getY();
float touchWidth = event.getTouchMajor();
float touchLength = event.getTouchMinor();


TextView textX = findViewById(R.id.touch_x);
TextView textY = findViewById(R.id.touch_y);
TextView textWidth = findViewById(R.id.touch_width);
TextView textLength = findViewById(R.id.touch_length);


textX.setText(Float.toString(touchX));
textY.setText(Float.toString(touchY));
textWidth.setText(Float.toString(touchWidth));
textLength.setText(Float.toString(touchLength));

return super.onTouchEvent(event);
}

我希望在触摸屏幕时看到手机上触摸宽度和触摸长度值的连续变化。

我遇到的另一个小问题:输出的长度和宽度是相同的,但我认为它们应该不同,因为文档说触摸区域是一个 eclipse 。

最佳答案

问题是我使用的硬件并不完全支持这些方法。顺便说一句,我在这个链接中受到卡米拉的启发:Android finger detection - Orientation and ellipse

然后我在 4 台 Android 设备上测试了我的程序:Nexus 5、Galaxy Note 8、Galaxy Tab S 和 Pixel 3 XL。

结果:

  1. Galaxy Note 8、Galaxy Tab S 和 Pixel 3 XL 可以区分长轴和短轴。

  2. 所有 4 台设备均无法通过 getOrientation() 方法返回有意义的值。

  3. Galaxy Note 8 的精度最高,然后是 Galaxy Tab S 和 Pixel 3 XL,Nexus 5 的精度较差。

关于java - getTouchMajor() 不精确 : I can not get real value about the touch area length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54221373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com