Disable / filter any touch event for layout

Is it possible to disable touch events for all views inside the layout by setting up ParentLayout. I know that this is possible by looking at each individual view contained in the layout, but it would be very useful if there was a way to do this for the full layout. I have already tried the following, but all in vain.

ParentLayout.setClickable(false); ParentLayout.onFilterTouchEventForSecurity(event); ParentLayout.onTouchEvent(event); ParentLayout.setOnTouchListener(l); ... 

and others in a similar way. Any help would be greatly appreciated.

+4
source share
2 answers
  • Disable all touch events in the parent view. dispatchTouchEvent() and onInterceptTouchEvent() can achieve this.
  • Set android:duplicateParentState="true" for the entire child view and set parent android:enable="false"
+4
source

Consider the following approach.

  public void disableTouch(ViewGroup viewGroup) { int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View view = viewGroup.getChildAt(i); view.setClickable(false); if (view instanceof ViewGroup) { disableTouch((ViewGroup) view); } } } 

It will go through all the children and disable the touch event for each of them.

+2
source

All Articles