0

I'm trying to make a bounding rectangle around an ImageView for collision detection. Unfortunately, I can only find code for sprites and not ImageViews. Is there a way to make a rectangle that goes outside of an image for an ImageView? One of the ImageViews moves through animation while the other one stays still.

David Elliott
  • 113
  • 1
  • 3
  • 10

1 Answers1

0

Using imageViews for move animation isn't best idea. It takes too many resources. However you can set width and height of imageView to WRAP_CONTENT and use sizes of ImageView as bounding rect

In your xml layout set android:layout_height and android:layout_width of your ImageView to "wrap_content". And when you need bounding rect of ImageView:

...
int[] l = new int[2];
imageView.getLocationOnScreen(l);
int x = l[0];
int y = l[1];
int w = imageView.getWidth();
int h = imageView.getHeight();
...

x, y, w ,h — required bounding rect in screen coordinates

nnesterov
  • 1,232
  • 1
  • 10
  • 27