如何禁用浏览的所有子元素捕获鼠标触摸事件 [英] How to disable all Child Elements of View to capture mouse touch event

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

问题描述

我想水平滑块菜单中的Andr​​oid(如Facebook)。

I'm trying to Horizontal Slider Menu in Android(like Facebook).

我只希望我的容器视图能够捕获鼠标触摸事件。

I want only my container View to be able to capture mouse touch event.

我曾尝试 setEnable(假)我所有的容器视图的子元素。但它引起的观点没有捕捉到触摸事件。

I have tried setEnable(false) all of child elements of my container view. But It cause the view not to capture touch event.

public void ChangeMenuVisibility() {
        int menuWidth = menu.getMeasuredWidth();
        // Ensure menu is visible
        menu.setVisibility(View.VISIBLE);
        int left = !menuOut ? 0 : menuWidth;
        container.smoothScrollTo(left, 0);
        menuOut = !menuOut;
        ViewUtils.enableDisableViewGroup(
                (ViewGroup) window.findViewById(R.id.main_content), !menuOut);
        window.findViewById(R.id.main_content).setEnabled(true);
    }
[ViewUtils.java]
    public static void enableDisableViewGroup(ViewGroup viewGroup,
            boolean enabled) {
        int childCount = viewGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View view = viewGroup.getChildAt(i);
            view.setEnabled(enabled);
            if (view instanceof ViewGroup) {
                enableDisableViewGroup((ViewGroup) view, enabled);
            }
        }
    }

我应该遵循哪些策略来实现这一目标。

What strategy should I follow to accomplish this.

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

覆盖 View.onInterceptTouchEvent()的ViewGroup ,不叫 super.onInterceptTouchEvent()并返回true。这将导致触摸事件不被流传下来的层次(到的的ViewGroup 的子女)。

Override View.onInterceptTouchEvent() in the ViewGroup, don't call super.onInterceptTouchEvent() and return true. This causes the touch events to not be passed down the hierarchy (to the children of the ViewGroup).

这篇关于如何禁用浏览的所有子元素捕获鼠标触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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