Android 设备的屏幕灵敏度
我在测试过程中遇到了一个非常奇怪的场景,也许你可以照亮我。
场景: 该应用程序包含在 Surfaceview 中,我在其中处理触摸事件。我的屏幕上有一个图像,用户将手指放在上面,然后将其收回。就像短按按钮一样。
出了什么问题:
三星 Galaxy S 配备 SuperAmoled 屏幕 - 触发的触摸事件为:向下然后向上。就像通常的 Nexus One,Desire 一样
- 触发的触摸事件是:向下、移动、移动、向上 移动手势很小,例如 +- 1 像素,但确实存在。现在想象一下,我有在 Move 事件中触发的代码。
因此,在我的 Galaxy S 上进行测试一切正常,在 Nexus 上进行测试则失败,因为它没有按预期做出反应。
我的问题:
- 有什么办法可以防止这种情况发生吗?
- 这是因为屏幕类型和灵敏度吗?
I have encountered a really weird scenario during my tests and maybe you can light me.
Scenario:
The application consists in a Surfaceview in which I handle the touch event. I have a image on the screen and the user put's his finger on it and then takes it back. Just like a short button pressing.
What goes wrong:
Samsung Galaxy S with SuperAmoled screen - the touch events fired are: Down and then Up. just like it is normally
Nexus One, Desire - the touch events fired are: Down, Move, Move, Up The move gesture is small like +- 1 px but there is. Now imagine the fact that I have code that is fired in Move event.
So testing on my Galaxy S everything works wonderful, testing on Nexus it fails as it doesn't react as supposed to.
My Questions:
- is there any way to prevent this ?
- is this because of screen type and sensitivity ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用布尔标志来防止代码在 Move 事件中运行,方法是在 down 事件中将标志设置为 true,然后调用方法。
Use boolean flag to prevent code to run in Move Event by setting flag to true in down event and then call the methods.
这是由于设备显示灵敏度所致。我在三星 Galaxy 10 和 10+ 上遇到了这种破坏行为。当手指不移动时,显示屏会捕获这些微动作并向我发送动作,这打破了通常的点击逻辑。
解决了这个问题,我实现了一个以点为单位的阈值(在我的例子中为 20 点,移动距离像素*远离向下位置的密度)以完全过滤掉这些微移动。
仅针对第一个移动事件检查阈值。因此,在超过阈值之前,所有移动都会被忽略,但如果移动最终超过阈值,则所有进一步的移动都会被接受,直到下一个手指按下事件。
This is due to device display sensitivity. I met this breaking behaviour on samsung galaxy 10 and 10+. When the finger was just not moving the display was capturing those micro-movements and sending me moves, breaking usual tap logic.
Solved this my implementing a threshold in points (20pts in my case, movement distance pixels*density away from the DOWN location) to totally filter out those micro-movements.
The threshold would be checked for the first Move event only. So until the threshold is outpassed all movements are ignored, but if the Move is finally depassing the threshold all further movements are accepted until the next finger down event.