且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何知道在Android中移动一个图像时两个图像是否相交?

更新时间:2022-11-17 18:32:36

您应该能够使用Rect.intersects(Rect, Rect),例如以下示例:

You should be able to use Rect.intersects(Rect, Rect), like this example:

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
} 

引用为 查看全文