我不是在问如何处理触摸事件,而是在幕后发生了什么?如果有几个嵌套的小部件,他们看到的事件是什么顺序?开发人员是否可以控制它?理想情况下,我想要一个关于这个主题的文件.
我想跟踪屏幕上的手指触摸.所以我所做的就是在MotionEvent触发时开始记录位置ACTION_DOWN,但我怎么知道动作何时结束ACTION_CANCEL,或者ACTION_UP?
它们之间的确切区别是什么?
我有一个顶级ViewGroup,我称它为SliderView,我想在其中检测滑动。这通常可以正常工作,但是一个奇怪的失败仍然存在。
SliderView的本质是重写onInterceptTouchEvent,并且在用户实际滑动后,返回“ true”以防止其他视图占用MotionEvent。这是一段代码:
public class SliderView extends ViewGroup
{
enum MoveState { MS_NONE, MS_HSCROLL, MS_VSCROLL };
private MoveState moveState = MoveState.MS_NONE;
... other code ...
public boolean onInterceptTouchEvent(MotionEvent e)
{
final int action = e.getAction();
switch (action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
moveState = MoveState.MS_NONE;
break;
case MotionEvent.ACTION_MOVE:
if (moveState == MoveState.MS_NONE)
{
if (motion is horizontal)
{
moveState = MoveState.MS_VSCROLL;
return true;
}
else
moveState = MoveState.MS_VSCROLL; // let child window handl MotionEvent
}
else if (moveState == MoveState.MS_HSCROLL) …Run Code Online (Sandbox Code Playgroud) android scrollview touch-event android-linearlayout motionevent