android - 如何知道两张图片是否相交而一张图片在android中移动?

标签 android android-imageview android-image ontouchlistener android-gesture

在我的应用程序中,我使用 onTouchListener 在屏幕上移动图像。

我在同一 View 中还有另外两张图片。 我的问题是,当移动图像触及任何其他图像时,我需要执行特定操作 (这意味着如果图像相交,则执行某些操作)。

如何实现?请尽快帮助我

提前致谢。

最佳答案

你应该能够使用 Rect.intersects(Rect, Rect),就像这个例子:

Rect myViewRect = new Rect();
myView.getHitRect(myViewRect);

Rect otherViewRect1 = new Rect();
otherView1.getHitRect(otherViewRect1);

Rect otherViewRect2 = new Rect();
otherView2.getHitRect(otherViewRect2);

if (Rect.intersects(myViewRect, otherViewRect1)) {
  // Intersects otherView1
}

if (Rect.intersects(myViewRect, otherViewRect2)) {
  // Intersects otherView2
} 

引用是 here .

关于android - 如何知道两张图片是否相交而一张图片在android中移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18398198/

相关文章:

android - 在 ImageView 中为 scaleType ="centerCrop"设置动画

java - 如何存储应用程序的静态核心数据?

android - 如何在android中制作谷歌地图?

android - NestedScrollView 的 smoothScrollTo() 行为怪异

android - 我怎样才能在android中获得我的 View 的中心x,y?

android - "Bitmap too large to be uploaded into a texture"

java - green dao 如何使用一次查询四个属性

android - 删除图像 ListView 中不必要的空格

android - 如何在android中安全地存储图像和视频以便其他应用程序无法使用?

java - 具有可点击区域的图像