android - How can you detect which view you are passing over when performing a touch event? -
i want know how can detect child views if move view 1 viewgroup viewgroup, particularly when doing touch event. there method can call let me know views i'm "hovering" over?
what i'm doing right when detect action_move event on view i'm raising top level parent can move , drawn within entire window ( , not inside it's original parent bounds ), want move view across different viewgroup , on action_up attach view viewgroup.
inspired ami's response, discovering motionevent#getx()/gety() along view#gettop()/etc return coordinates wrt parent view, ended doing following below operate in screen coordinates, allowing me work across viewgroups:
private boolean inregion(float x, float y, view v) { v.getlocationonscreen(mcoordbuffer); return mcoordbuffer[0] + v.getwidth() > x && // right edge mcoordbuffer[1] + v.getheight() > y && // bottom edge mcoordbuffer[0] < x && // left edge mcoordbuffer[1] < y; // top edge }
whose usage inside ontouchlistener e.g.:
boolean inside = inregion(event.getrawx(), event.getrawy(), targetview);
Comments
Post a Comment