GenericMotion - Action Down不触发

时间:2016-12-21 22:32:28

标签: android imageview xamarin.android gesture

我想追踪通过触摸我的ImageView开始的手指的整个动作。我发现GenericMotion事件应该是正确使用的事件。

我应该做什么(或避免)在GenericMotion事件中获取操作,向下移动和向上移动?即使我开始触摸ImageView的中心,我也只获得HoverEnter,HoverMove和HoverExit动作。

Android: OnTouch, MotionEvent.ACTION_MOVE is not recognized?

在这里我了解到,如果不处理Down动作,我就无法完成剩下的动作,但我没有得到Down动作!

private void OnPlayerInfoRatingGenericMotion(object sender, View.GenericMotionEventArgs e)
{
    //goes here only with hover actions
    if (e.Event.Action==MotionEventActions.Down)
    {
        //never goes here
    }
    if (e.Event.Action==MotionEventActions.Move)
    {
        //never goes here
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

GenericMotion无法检测到手指的手势。我认为它仅用于报告移动事件。您可以在此处参考document

例如,您可以将图片视图从上到下移动,然后GenericMotion可以检测到"移动"动作。

如果您想检测您的手指事件,我认为您可以实现OnTouchListener

例如:

imgview.SetOnTouchListener(new MyTouchListener());

实现MyTouchListener:

public class MyTouchListener: Java.Lang.Object, View.IOnTouchListener
{
    public bool OnTouch(View v, MotionEvent e)
    {
        throw new NotImplementedException();
    }

    public bool OnTouchEvent(View v, MotionEvent e)
    {
        if (e.Action == MotionEventActions.Down)
        {
            Log.Debug("Mike", "Down");
            Console.WriteLine("Down");
            return true;
        }
        if (e.Action == MotionEventActions.Up)
        {
            Log.Debug("Mike", "Up");
            Console.WriteLine("Up");
            return true;
        }
        if (e.Action == MotionEventActions.Move)
        {
            Log.Debug("Mike", "Move");
            Console.WriteLine("Move");
            return true;
        }

        return false;
    }
}

此外,您可以IOnGestureListener来检测您的手势。