GenericMotion - Action Down not firing

纵饮孤独 提交于 2019-12-25 04:11:39

问题


I want to trace the whole movement of a finger that started by touching my ImageView. I found that GenericMotion event should be the correct one to use.

What am I supposed to do (or to avoid) to get Actions Down, Move and Up in GenericMotion event? I get only HoverEnter, HoverMove and HoverExit actions, even if I start with touching the center of my ImageView.

Android: OnTouch, MotionEvent.ACTION_MOVE is not recognized?

Here I learned that without handling Down action I can't get the remaining actions, but I don't get the Down action!

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
    }
}

What am I doing wrong?


回答1:


GenericMotion can not detect the gesture of your finger. I think it is only used to report for movement event. You can refer to the document here.

For example , You can move your imageview from top to bottom then the GenericMotion can detect the "move" action.

If you want to detect your finger event I think you can achieve OnTouchListener.

For example:

imgview.SetOnTouchListener(new MyTouchListener());

achieve 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;
    }
}

Also you can achieve IOnGestureListener to detect your gesture.



来源:https://stackoverflow.com/questions/41273025/genericmotion-action-down-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!