处理拦截触摸事件,并且不延长的ViewGroup事件、ViewGroup

由网友(夏日⊕樱花)分享简介:我有一个 RelativeLayout的这个布局有在这近10次。I have a one RelativeLayout and this layout is having nearly 10 views in it.我已经设置 OnTouchListener 来此布局,做一些工作,并返回真。I have set...

我有一个 RelativeLayout的这个布局有在这近10次。

I have a one RelativeLayout and this layout is having nearly 10 views in it.

我已经设置 OnTouchListener 来此布局,做一些工作,并返回

I have set OnTouchListener to this Layout and doing some work in it and returning true.

这监听器工作正常,当我触摸那里有没有查看布局(平均在空白区域)。如果我谈谈这个布局的子视图,该监听器不点火...

this listener is working fine when I touch the layout where there are no View (mean on Empty area). If I touch on child views of this layout, this listener is not firing...

和从文档,我明白了,我们可以覆盖 onInterceptTouchEvent()通过扩展的ViewGroup(所以这里RelativeLayout的),并处理触摸事件之前,孩子的意见消耗本次活动..

and from the documentation, I understood that we can override onInterceptTouchEvent() by extending ViewGroup (so here RelativeLayout) and handle touch events before child views consume this event...

这会做的伎俩,但我需要修改,​​我用我的CustomRelativeLayout取代RelativeLayout的需要此功能很多的XML文件。

this will do a trick, but I need to modify many xml files where I need this functionality by replacing RelativeLayout with my CustomRelativeLayout.

所以我的问题是:

有没有什么办法来处理触摸事件的 RelativeLayout的(ofcourse的ViewGroup)的 RelativeLayout的子视图之前消耗事件?我不希望延长 RelativeLayout的 ...

is there any way to handle touch event for RelativeLayout (ofcourse ViewGroup) before child views in RelativeLayout consumes event? I don't want to extend RelativeLayout...

推荐答案

尝试重写

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    return super.dispatchTouchEvent(ev);
}

活动的。 此方法是第一个过程的触摸事件。 但在这种情况下,你需要和意见当前坐标工作

of Activity. This method is the first that process touch events. But in this case you need to work with current coordinates of views

阅读全文

相关推荐

最新文章