detect if views are overlapping

前端 未结 6 1398
名媛妹妹
名媛妹妹 2020-12-13 14:59

I have problem with drawing views on another size screens! I need method which has two parameters of View type. And return true if first view overlapping on second view, an

6条回答
  •  無奈伤痛
    2020-12-13 15:27

    To help you in a VERY simple way. I will give a logic code which will undoubtedly detect two colliding views, even if they are moving. This can work for Bitmaps, ImageViews, and just about anything you can think of. Here it is and this is all:

    //LET'S SAY WE DETECT IF PLAYER COLLIDES WITH ENEMY
    if((Math.abs(yourviewid.getY() - yoursecondviewid.getY()) < 75) 
         && (Math.abs(yourviewid.getX() - yoursecondviewid.getX()) < 75)){
        //DO YOUR STUFF HERE
    }
    

提交回复
热议问题