How can I disable all touch events on all children of a ViewGroup?
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;
}
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.
jul
Updated on June 05, 2022Comments
-
jul almost 2 years
I've got a
FrameLayout
container containing many things (includingScrollView
,WebView
,ViewPager
...).I would like to be able to trigger the onClick event on this container, but it seems that some of
ScrollView
,WebView
andViewPager
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...How can I disable all touch events on the container's children in order to be able to trigger onClick anywhere in it?
UPDATE
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.
Thanks
-
jul about 12 yearsThe ScrollView still scroll, and the container onClick is still not triggered when disabling all children... :(
-
Rafael T about 12 yearsshouldn't the scrollView scroll? If not you can test
View v
above if it is a scrollView and disable scrolling there. I can't tell you more with such less informations. You could at least post your XML to let me see, what might be the problem -
jul about 12 yearsI've updated my question with why I want to do that. I don't think more information is needed: I just want to be able to trigger the onClick event on a viewgroup containing views like scrollview, viewpager...