How can I disable all touch events on all children of a ViewGroup?

前端 未结 2 1198
囚心锁ツ
囚心锁ツ 2020-12-29 11:33

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

I would l

2条回答
  •  佛祖请我去吃肉
    2020-12-29 11:48

    You could disable them like this:

    FrameLayout parent = (FrameLayout)findViewById(some_id);
    disableChildsOnTouch(parent)
    
    
    public void disableChildsOnTouch(ViewGroup viewGroup){
        int cnt = viewGroup.getChildCount();
        for (int i = 0; i < cnt; i++){
            View v = viewGroup.getChildAt(i);
            if (v instanceof ViewGroup){
                disableChildsOnTouch((ViewGroup)v);
            } else {
                v.setOnTouchListener(null);
                v.setOnClickListener(null);
                //v.SETYOURLISTENER(null)
            }
        }
    }
    

提交回复
热议问题