Horizo​​ntalScrollView 上的 OnTouch 事件 - 当控件失去焦点/用户手指失控时

OnTouch events on HorizontalScrollView - when control lost focus / user finger is out of control

我有带水平滚动视图的图库。当用户滑动滚动视图时,我会监听 OnTouch 事件并播放动画等。

基本上:

public bool OnTouch(Android.Views.View v, Android.Views.MotionEvent e)
{
    switch (e.Action)
    {
        case MotionEventActions.Down:
            System.Console.WriteLine("OnTouch > Down");
            // Start Animation (change alpha imageviews in list to 100%)
            break;
        case MotionEventActions.Move:
            System.Console.WriteLine("OnTouch > Move");
            // Do something...
            break;
        case MotionEventActions.Up:
            System.Console.WriteLine("OnTouch > Up");
            // End Animation (change alpha imageviews in list to 50%)
            break;
    }
    return true;
}

但是用户可以选择在控件中启动 OnTouch 事件,但在将他的触摸移出焦点控件时结束。因此操作 'Up' 不会运行。问题是如何处理这种情况 - 我想知道这种情况何时会出现并以编程方式调用与实际操作相同的代码 'Up'.

因此事件列表如下所示:

你必须使用 MotionEventActions.Cancel:

public bool OnTouch(Android.Views.View v, Android.Views.MotionEvent e)
{
    switch (e.Action)
    {
        case MotionEventActions.Down:
            System.Console.WriteLine("OnTouch > Down");
            // Start Animation (change alpha imageviews in list to 100%)
            break;
        case MotionEventActions.Move:
            System.Console.WriteLine("OnTouch > Move");
            // Do something...
            break;
        case MotionEventActions.Up:
            System.Console.WriteLine("OnTouch > Up");
            // End Animation (change alpha imageviews in list to 50%)
            break;
        case MotionEventActions.Cancel:
            System.Console.WriteLine("OnTouch > Cancel");
            // End Animation (change alpha imageviews in list to 50%)
            break;
    }
    return true;
}

public static final int ACTION_CANCEL

Constant for getActionMasked(): The current gesture has been aborted. You will not receive any more points in it. You should treat this as an up event, but not perform any action that you normally would.