我想拦截给定布局中的每个触摸事件。

然后我要记录事件

并将事件传播到触摸区域中的任何可单击视图。

如果我只想消耗一次触摸事件,该怎么办?

我在其他SOF帖子中已经阅读过以使用此功能:


  (a)在顶部覆盖onInterceptTouchEvent(MotionEvent ev)方法
  级容器视图或(b)您可以覆盖
  Activity.onUserInteraction,但其中也包含键和轨迹球
  行动


但是我不确定首先会发生什么?事件是在根布局中处理还是启动其子级?

事件是否总是从下层传播到上一层(其子视图为父视图)?

最佳答案

您是否尝试覆盖Activity.dispatchTouchEvent(MotionEvent ev)

从文档http://developer.android.com/reference/android/app/Activity.html#dispatchTouchEvent(android.view.MotionEvent)

Called to process touch screen events. You can override this to intercept all touch screen events before they are dispatched to the window. Be sure to call this implementation for touch screen events that should be handled normally.

关于java - 如何在整个Android屏幕上拦截每个触摸事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23544755/

10-09 07:32
查看更多