本文介绍了Android的ACTION_MOVE阈值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序,包括在屏幕上使用一个手指,或者最终手写笔书写。我有这部分工作。在ACTION_DOWN,开始绘制;在ACTION_MOVE,增加线段;在ACTION_UP,完成行。

I'm writing an app that involves writing on the screen using one's finger, or eventually a stylus. I have that part working. On ACTION_DOWN, starts drawing; on ACTION_MOVE, adds line segments; on ACTION_UP, finishes line.

问题在于ACTION_DOWN之后,显然指针需要从那里开始(基本上围绕起点20×框),以开始发送ACTION_MOVE事件移动超过10像素的路程。离开箱后,移动事件都相当精确。 (我想通了10像素的东西通过测试。),因为这意味着用于书写或绘画,10个像素是一个相当显著损失:这取决于你想有多小写,你可以失去的第一个字母或两种。我一直没能找到任何关于它 - 仅在一个论坛或两个一对夫妇的帖子,如http://android.modaco.com/topic/339694-touch-input-problem-not-detecting-very-small-movements/page_pid_1701028#entry1701028.这似乎是$在某些设备或系统,而不是别人p $ psent。没有想法,如何得到它去掉,当你拥有了它,虽然。

The problem is that after ACTION_DOWN, apparently the pointer needs to move more than 10 pixels away from where it started (basically a 20x20 box around the starting point) in order to begin sending ACTION_MOVE events. After leaving the box, the move events are all quite accurate. (I figured out the 10 pixel thing by testing it.) Since this is meant to be used for writing or drawing, 10 pixels is a fairly significant loss: depending on how small you're trying to write, you can lose the first letter or two. I haven't been able to find anything about it - only a couple posts on a forum or two, like http://android.modaco.com/topic/339694-touch-input-problem-not-detecting-very-small-movements/page_pid_1701028#entry1701028. It seems to be present on some devices or systems and not others. No ideas as to how to get rid of it when you have it, though.

我使用的Galaxy Tab 10.1,与Android 3.1。我已经尝试了几种不同的东西,试图摆脱它:我已经试过设置事件的COORDS别的东西,看看我能骗就以为光标是在不同的地方;我试图重新调度事件与COORDS改变了(我的处理程序作出反应,新的点,但仍没有到运动的10像素的半径回应。)我已经通过源$ C ​​$ C搜索到的任何引用的效果,却找不着(虽然我认为这是从不同的Andr​​oid版本 - code为3.1尚未发布,它是)我搜索查询指针的当前状态的方法,所以我可以有一个计时器赶上变化,直到指针跨过的门槛。找不到任何方式获取指针COORDS没有相应的运动盛会。毫无效果。有谁知道这事,或有任何意见或变通?谢谢你。

I'm using a Galaxy Tab 10.1, with Android 3.1. I've tried several different things to try to get rid of it: I've tried setting the event's coords to something else to see if I could trick it into thinking the cursor was in a different place; I tried re-dispatching the event with the coords changed (my handler reacted to the new points, but still didn't respond to movements in the 10-pixel radius.) I've searched through source code for any references to the effect, and found none (though I think it's from a different version of Android - code for 3.1 isn't released yet, is it?) I've searched for methods of querying the current state of the pointers, so I could just have a timer catch the changes until the pointer crossed the threshold. Couldn't find any way of getting pointer coords without a corresponding movement event. Nothing worked. Does anybody know anything about this, or have any ideas or work-arounds? Thank you.

- 更新:拖放事件表明了相同的阈值

-- Update: Drag and drop events show the same threshold.

推荐答案

我同意与发布者@passsy一部分,但得出不同的结论。首先提到,在 mTouchSlop 是我们感兴趣的,并通过 ViewConfiguration.get(上下文)暴露值.getScaledTouchSlop();

I agree in part with the post by @passsy but come to a different conclusion. Firstly as mentioned, the mTouchSlop is the value that we are interested in and is exposed via ViewConfiguration.get(context).getScaledTouchSlop();

如果您检查了Android源ViewConfiguraton,默认值 TOUCH_SLOP 8DIP ,但该意见提到,这个值是一个备用而已,与实际值的定义时,Android操作系统的特定装置被安装。 (它可能比这个值更多或更少。它似乎仍然适用于Galaxy Tab的设备)

If you check the Android source for the ViewConfiguraton, the default value for TOUCH_SLOP is 8dip, but the comments mention that this value is a fallback only, and the actual value is defined when the Android OS for that specific device is built. (it may be more or less than this value. It appears to hold true for the Galaxy Tab devices)

更具体到code样品中, mTouchSlop 值从阅读 ViewConfiguration 查看被初始化,但该值仅在的onTouchEvent 方法来访问。如果扩展查看并重写此方法(不调用),那么行为 mTouchSlop 查看类不再适用。

More specific to the code sample, the mTouchSlop value is read from the ViewConfiguration when the View is initialised, but the value is only accessed in the onTouchEvent method. If you extend View and override this method (without calling super) then the behaviour of mTouchSlop in the View class is no longer relevant.

更能说明问题(我们)是改变Android的设置时覆盖触摸事件在屏幕上,用小拖不注册为移动事件的触摸,由一个事实,即从Android操作系统的十字线做突出不动。从这我们的结论是,最小的拖动距离的正在执行的操作系统级别和应用程序将永远不会知道拖动事件比 TOUCH_SLOP 值。你也应该知道, TOUCH_SLOP 不应该直接使用,而API去precates的 getTouchSlop 方法和建议 getScaledTouchSlop 这需要在设备屏幕尺寸和像素密度考虑进去。这方面的一个副作用是,实际的最小冲程长度感知不同设备上可能会发生变化。例如,在Galaxy Tab的2.0 7.0感觉就像我们能够得出使用相同的code基短最低招上的Galaxy Tab 2.0 10.1上运行时不是

More telling (to us) was that when changing the Android settings to overlay touch events on the screen, a touch with a small drag does not register as a motion event, highlighted by the fact that the crosshairs from the Android OS do not move. From this our conclusion is that the minimal drag distance is being enforced at the OS level and your application will never be aware of drag events smaller than the TOUCH_SLOP value. You should also be aware that TOUCH_SLOP should not be used directly and the API deprecates the getTouchSlop method and recommends getScaledTouchSlop which takes the device screen size and pixel density into account. A side effect of this is that the actual minimum stroke length as perceived on different devices may vary. eg on a Galaxy Tab 2.0 7.0" it feels like we are able to draw shorter minimum strokes using the same code base than when running on a Galaxy Tab 2.0 10.1"

您应该也知道,(如果你找到一个方法来改变这个值),该值决定的Andr​​oid系统,水龙头和中风之间如何区分。也就是说,如果你点击屏幕,但你的手指会轻微移动而进行的水龙头,这将是PTED为龙头跨$ P $如果移动小于 TOUCH_SLOP ,但作为一个行程,如果它移动了比 TOUCH_SLOP 。因此,设置的 TOUCH_SLOP ,以较小的值将增加机会,一个水龙头将PTED为中风跨$ P $。

You should also be aware that (if you find a way to alter this value), this value determines how Android systems distinguish between taps and strokes. That is if you tap the screen but your finger moves slightly while performing the tap, it will be interpreted as a tap if it moved less than TOUCH_SLOP, but as a stroke if it moved more than TOUCH_SLOP. Therefore setting TOUCH_SLOP to a smaller value will increase the chance that a tap will be interpreted as a stroke.

我们的自己的结论是,这个最小距离是不是可以在实践中被改变,是我们需要活的东西。

Our own conclusion is that this minimum distance is not something that can be changed in practice and is something we need to live with.

这篇关于Android的ACTION_MOVE阈值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:43
查看更多