How can i get center x,y of my view in android?

前端 未结 5 1796
温柔的废话
温柔的废话 2020-12-29 19:29

I am attaching an imageview up on my frame layout. Here i want to get my imageview center co-ordinates. i will use that same co-ordinates to set my imageview in next layout.

5条回答
  •  长情又很酷
    2020-12-29 20:16

    centre of the imageView will be

     centreX=imageView.getX() + imageView.getWidth()  / 2;
     centreY=imageView.getY() + imageView.getHeight() / 2;
    

    but make sure you call it after the imageView created

提交回复
热议问题