Handling Intercept touch event without extending ViewGroup Handling Intercept touch event without extending ViewGroup android android

Handling Intercept touch event without extending ViewGroup


Try to override

@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {    return super.dispatchTouchEvent(ev);}

of Activity. This method is the first that process touch events.But in this case you need to work with current coordinates of views


While not necessarily being ideal, this works well for smaller layouts that won't have dynamic content.

In xml, set android:clickable="false" to all descendants of the ViewGroup in the layout (including nested ViewGroups and their children). Each child that gets clicked on will then propagate the click to its parent, eventually getting to the ViewGroup's default touch handlers. Make sure to set root ViewGroup, where you want to get the click events as android:clickable="true" or viewgroup.setClickable(true)

If you add views dynamically, make sure to call view.setClickable(false); before adding it to the view hierarchy.


Try add onTouchListener to RelativeLayout

RelativeLayout rl = (RelativeLayout) findViewById( R.id.relativeLauout );    rl.setOnTouchListener( new OnTouchListener() {        @Override        public boolean onTouch(View v, MotionEvent event) {            // do something            return false;        }    });

or use method onTouchEvent from Activity

@Overridepublic boolean onTouchEvent(MotionEvent event) {    // TODO Auto-generated method stub    return super.onTouchEvent(event);}