Search code examples
javaandroiddraggableontouchlistener

How to check position of dragging view is lying over the another view or not


enter image description here

I have these round dragable buttons i am using set setTranslationX() setTranslationY() inside the ontouch event for drag functionality. How i can get to know that if any button dragged to middle of the icon, is lying over the middle icon or not?


Solution

  • Thank you @Dheerubhai Bansal Finally i am done with using this collision method. Working fine to find intersection between two views

    public boolean CheckCollision(View v1, View v2) {
        Rect myViewRect = new Rect();
        v1.getHitRect(myViewRect);
        Rect otherViewRect1 = new Rect();
        v2.getHitRect(otherViewRect1);
        return Rect.intersects(myViewRect, otherViewRect1);
    }