【发布时间】:2014-01-27 15:13:39
【问题描述】:
我有一个RelativeLayout,这个布局有近 10 个视图。
我已将OnTouchListener 设置为此布局并在其中做一些工作并返回true。
当我触摸没有视图的布局时,这个监听器工作正常(意味着在空白区域)。如果我触摸此布局的子视图,则此侦听器不会触发...
从文档中,我了解到我们可以通过扩展 ViewGroup(所以这里是 RelativeLayout)覆盖 onInterceptTouchEvent() 并在子视图使用此事件之前处理触摸事件...
这会起到作用,但我需要修改许多需要此功能的 xml 文件,方法是用我的 CustomRelativeLayout 替换 RelativeLayout。
所以我的问题是:
在RelativeLayout 中的子视图消耗事件之前,有什么方法可以处理RelativeLayout(当然是ViewGroup)的触摸事件?我不想扩展RelativeLayout...
【问题讨论】:
-
没有这样的方法:你必须扩展RelativeLayout
标签: android touch-event ontouchlistener