I'm trying to make a collision detection system for two ImageViews, but I can't seem to figure it out. I've tried doing several things from StackOverflow and other places, but they don't work. One ImageView stays still and the other moves toward it (it's animated, not a sprite). They don't do anything when the collide, though. Do I need to make them sprites or drawables on a canvas or something?

  • \$\begingroup\$ Hello and welcome to GDSE. It's somewhat hard to answer, because you say that you have used several things, yet you don't mention what you have tried. \$\endgroup\$ – Katu Jul 25 '14 at 4:33

Get information (dimensions, coordinates) of two imageviews, then use rectangle intersection condition. Assume that two rectangles A, B with coordinate of top-left and buttom-right as follow:

Rectangle A: (Xa1, Ya1) ; (Xa2, Ya2)
Rectangle B: (Xb1, Yb1) ; (Xb2, Yb2)

Overlap condition:

((Xb1 - Xa2)(Xb2 - Xa1) <= 0) && ((Yb1 - Ya2)(Yb2 - Ya2) <= 0)

Refer the below site for some guidance:


It explains bounding shapes that will be used to check for collision. In the case of our robot, we will be using four bounding rectangles.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.