如何禁用 ViewGroup 的所有子项上的所有触摸事件? [英] How can I disable all touch events on all children of a ViewGroup?

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

问题描述

我有一个 FrameLayout 容器,其中包含许多东西(包括 ScrollViewWebViewViewPager...).

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

我希望能够在这个容器上触发 onClick 事件,但似乎有一些 ScrollViewWebViewViewPager拦截touch事件,因为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?

更新

这个想法是像 Android 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) 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) 方法.

According to the android documentation this means that your ViewGroup will always intercept all the touch events and don't dispatch them to the children. All of them will be directed to the ViewGroup.onTouchEvent(MotionEvent ev) method of your ViewGroup.

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

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