Check Touch out of relative layout

Check the x,y position on the screen you touch if it out of RelativeLayout or not..


Step 1: In your activity, oerride this method: dispatchTouchEvent

Step 2: Find your layout via RelativeLayout yourlayoutID = (RelativeLayout) findViewById(….bla bla bla);

Step 3: View your new method:

public boolean dispatchTouchEvent(MotionEvent ev) {

float touchPointX = ev.getX();
float touchPointY = ev.getY();
int[] coordinates = new int[2];
if (touchPointX < coordinates[0] || touchPointX > coordinates[0] + yourLayout.getWidth() || touchPointY < coordinates[1] || touchPointY > coordinates[1] + yourLayout.getHeight()){
//Do Your ACTION
return super.dispatchTouchEvent(ev);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s