检测视图碰撞并防止覆盖

当我正在使用Kotlin android框架进行一个益智游戏时,我被困在了一点,当我无法弄清楚如何防止imageViews在移动时互相重叠时,我尝试了很多解决方案,没有任何工作,如果任何人可以告诉我如何防止它们重叠或告诉我如何检测碰撞的正确方法。

这里是我用来检测碰撞的代码:

//onCreate getRundomPosition() //this method is used to put the imageView in some random position imageView.getDrawingRect(rc1) imageView2.getDrawingRect(rc2) imageView3.getDrawingRect(rc3) imageView4.getDrawingRect(rc4) imageView5.getDrawingRect(rc5) imageView6.getDrawingRect(rc6) imageView7.getDrawingRect(rc7) //the function I use to check collision it's called after a swipe event fun checkIntersection(rc:Rect):Boolean{ var b:Boolean if(Rect.intersects(rc,rc1)) b=true else if(Rect.intersects(rc,rc2)) b=true else if(Rect.intersects(rc,rc3)) b=true else if(Rect.intersects(rc,rc4)) b=true else if(Rect.intersects(rc,rc5)) b=true else if(Rect.intersects(rc,rc6)) b=true else if(Rect.intersects(rc,rc7)) b=true else b=false return b }