I have two ImageViews and I want to detect the intersection between the two images. So I decided to find a solution online, I'm using getDrawingRect to draw a rectangle, wrapping with the ImageView. However, I have a problem when I run the codes. Both imageViews don't get intersect but Rect.Intersect return true. Always true, no matter they got intersect or not. Below is my codes.
Intersection between two images
Rect rc1 = new Rect();
rc1.left = arrow.getLeft();
rc1.top = arrow.getTop();
rc1.bottom = arrow.getBottom();
rc1.right = arrow.getRight();
arrow.getDrawingRect(rc1);
Rect rc2 = new Rect();
rc2.left = view.getLeft();
rc2.top = view.getTop();
rc2.bottom = view.getBottom();
rc2.right = view.getRight();
view.getDrawingRect(rc2);
if (Rect.intersects(rc1,rc2))
{//intersect!}
else{//not intersect}
First ImageView
<ImageView
android:id="@+id/needle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/spinnerFrame"
android:layout_centerHorizontal="true"
android:src="@drawable/arrow_top" />
Second ImageView
<ImageView
android:id="@+id/letter_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/needle"
android:layout_marginLeft="-10dp"
android:layout_marginTop="-10dp"
android:layout_toRightOf="@+id/needle"
android:scaleType="matrix"
android:src="@drawable/letter_a" />