如何禁用一个的ViewGroup的所有儿童都触摸事件? [英] How can I disable all touch events on all children of a ViewGroup?

查看:285
本文介绍了如何禁用一个的ViewGroup的所有儿童都触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的FrameLayout 容器包含很多东西(包括滚动型的WebView ViewPager ...)。

I've got a FrameLayout container containing many things (including ScrollView, WebView, ViewPager...).

我希望能够触发这个容器中的onClick事件,但似乎有些滚动型的WebView的 ViewPager 拦截触摸事件,因为onClick事件是当我点击的容器没有任何人的部分仅触发...

I would like to be able to trigger the onClick event on this container, but it seems that some of ScrollView, WebView and ViewPager intercept the touch event, because the onClick event is only triggered when I click on the parts of the container that do not have any of them...

如何禁用,以便能够触发的onClick在任何地方在容器的孩子们触摸事件?

How can I disable all touch events on the container's children in order to be able to trigger onClick anywhere in it?

更新

的想法是有类似的任务管理器中的Andr​​oid 3.2,即其中该应用的当前屏幕可见被示为减小的图标,可以点击

The idea is to have something like the task manager in Android 3.2, i.e. where the current visible screen of the app is shown as a reduced icon, that can be clicked.

感谢

推荐答案

可能是我误会了一些东西,但是我想回答你的问题很简单: 如果你不希望派遣无触摸事件给孩子 - 所以你只需要重写 ViewGroup.onInterceptTouchEvent(MotionEvent EV) <一个href="http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29">API引用是这样的:

May be I have misunderstood something, but I guess the answer to your question is very simple: If you don't want to dispatch none of the touch events to the children - so you just need to override ViewGroup.onInterceptTouchEvent (MotionEvent ev) API reference like this:

public boolean onInterceptTouchEvent (MotionEvent ev){
    return true;
}

据android的文档,这意味着你的ViewGroup将始终拦截所有触摸事件,并且不派遣他们的孩子。他们都将被引导到你的ViewGroup的 ViewGroup.onTouchEvent(MotionEvent EV)方法。

这篇关于如何禁用一个的ViewGroup的所有儿童都触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆