xamarin.forms - 如何在表单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);
}
解决方案
推荐阅读
- jar - 无法下载 builder.jar (com.android.tools.build:builder:3.2.0):没有可用于离线模式的缓存版本
- flutter - 一个奇怪的 Scrollview 警告...在 Flutter 中构建 apk 时产生问题
- node.js - Jest 的 globalSetup 使我的测试无法被识别
- excel - 在散点图中查找特定点的参考行号
- ruby-on-rails - 无法将 rails 应用程序推送到 heroku - 编译失败
- java - Kafka jaas 在 Flink 集群上验证失败
- java - JVM如何处理引用变量?
- time-series - x 轴上带有日期时间段(月-年)的散景图
- javascript - 如何将 JavaScript 生成的 div 元素放置在主体 div 元素中
- c++ - C++初始化基类