首页 > 解决方案 > 如何在表单android中检测DispatchTouchEvent方法中的单击

问题描述

我正在使用 DispatchTouchEvent 并且需要检测单击,因为考虑到下点和上点,当两者相同时,检测到单击。但这在某些 android 设备中运行良好,但在某些设备中,上下点存在像素差异。如何克服这一点?

         public override bool DispatchTouchEvent(MotionEvent e)
    {
        if (e.Action == MotionEventActions.Down)
        {  
            touchDownPoint = new Xamarin.Forms.Point(e.GetX(), e.GetY());
        }
        else if (e.Action == MotionEventActions.Up)
        {   
            var position = new Xamarin.Forms.Point(e.GetX(), e.GetY());               
            if (touchDownPoint == position) // this condition not gets satisfied in some devices
            {
                // single tap detected.
            }
        }
        else if (e.Action == MotionEventActions.Move)
        {              
        }

        return base.DispatchTouchEvent(e);
    }

标签: xamarin.formsxamarin.androidtouch

解决方案


推荐阅读