在我的应用程序中,我使用以下方法在屏幕上移动图像onTouchListener
.
我在同一视图中还有另外两张图像。
我的问题是,当移动图像接触任何其他图像时,我需要执行特定操作
(这意味着如果图像相交,则执行某些操作)。
如何实现这一点?请尽快帮助我
提前致谢。
你应该能够使用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 https://developer.android.com/reference/android/graphics/Rect.html#intersects%28android.graphics.Rect,%20android.graphics.Rect%29.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)