【发布时间】:2014-08-12 20:04:54
【问题描述】:
我有两个 ImageView,我想检测两个图像之间的交集。于是决定在网上找个解决办法,我用getDrawingRect画一个矩形,用ImageView包裹。但是,我在运行代码时遇到了问题。两个 imageViews 都没有相交,但 Rect.Intersect 返回 true。始终正确,无论它们是否相交。 以下是我的代码。
两张图片的交集
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}
第一个 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" />
第二个图像视图
<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" />
【问题讨论】:
-
也许这是一个重复的问题。见stackoverflow.com/questions/115426/…
标签: java android imageview intersect rect