In my application, i am moving image around the screen by using onTouchListener
.
I have another two images in the same view. My problem is that, when the moving image, touches any of the other images, i need to perform a certain action (that means if images are intersected, then do something).
How can this be achieved?.Please help me asap
Thanks in Advance.
In onTouch with move action you can get rectangle bound of your moving images and another. Check if your moving rect intersect with another by intersect function like: Rect movingBound = new Rect(); Rect[] anotherImagesBound = new Rect[...]
get Rect bound by:
same with another imageView. loop in the anotherImagesBound and check :
Note: you must update movingBound in every touch action, but your another ImageView you should get once. Hope this help
You should be able to use
Rect.intersects(Rect, Rect)
, like this example:Reference is here.
When you move your image in the onTouch listener, check for rectangle intersection between View a and View b using: