android - Check Touch out of relative layout -
i want check touch x,y position in activity know out of relativelayout or not. override ontouchevent activity not working fine.
you have this.. in activity have override
dispatchtouchevent so in oncreate find view
relativelayout yourlayout = (relativelayout) findviewbyid(r.id.yourlayout); and
@override public boolean dispatchtouchevent(motionevent ev) { float touchpointx = ev.getx(); float touchpointy = ev.gety(); int[] coordinates = new int[2]; yourlayout.getlocationonscreen(coordinates); if (touchpointx < coordinates[0] || touchpointx > coordinates[0] + yourlayout.getwidth() || touchpointy < coordinates[1] || touchpointy > coordinates[1] + yourlayout.getheight()){ //do action } return super.dispatchtouchevent(ev); }
Comments
Post a Comment