在我的应用程序中,我使用 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/