我正在开展一个项目,我必须移动一个图像,还有两个图像,并且在这些静止图像的重叠中,我必须执行任务。中间图像是可移动的,而其他图像是静止的(就像我们在锁屏中一样)。
我已完成移动部件,但我无法重叠图像。我不知道当移动图像与静止图像重叠时我们会发现它是如何发现的。
有人对此查询有任何建议吗?
答案 0 :(得分:0)
我认为对类似但不完全相同的问题的回答可能有所帮助!
Collision Detection between two images in Java
修改强>
这方面的一个例子可能是(我真的没有做太多的Android开发,所以请原谅我,如果这不起作用):
用这样的方式覆盖onWindowFocusChanged(boolean focus)
。
import android.graphics.Rect;
imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView2 = (ImageView) findViewById(R.id.imageView2);
Rect rect1 = new Rect();
imageView1.getDrawingRect(rect1);
Rect rect2 = new Rect();
imageView2.getDrawingRect(rect2);
if (Rect.intersects(rect1, rect2) {
//intersected
}
答案 1 :(得分:0)
您可以拍摄照片的x,y,宽度和高度值并进行比较。在窗口中想象一个网格,其中图片的4个顶点是x,y,宽度和高度值并进行比较。