如何在 Xamarin.Android 中检测 View
的双击事件?我在使用 TouchListener
时失败了。
有一个SO answer表示双击不是 Android 模式。
对于 native Android (Java),有一个 answer ,但我想在 Xamarin (C#) 中执行此操作。
最佳答案
在 C# 中做这个任务太容易了。你是这个世界的新手,所以我给你确切的解决方案。
首先,您不必为此创建新的自定义 View 。
创建一个类
private class GestureListener : GestureDetector.SimpleOnGestureListener
{
public override bool OnDown(MotionEvent e)
{
return true;
}
public override bool OnDoubleTap(MotionEvent e)
{
return true;
}
}
现在只需编写这段代码。
GestureDetector _gestureDetector = new GestureDetector (_context, new GestureListener ());
_gestureDetector.DoubleTap += (object sender, GestureDetector.DoubleTapEventArgs e) => {
//apply double tap code here
};
//apply touch to your view
View1.Touch += (object sender, View.TouchEventArgs e) => {
_gestureDetector.OnTouchEvent (e.Event);
};
希望对你有帮助
关于c# - 双击 View 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32655088/