Search code examples
androidandroid-imageview

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


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. Please suggest me how to get the center co-ordinates of my imageview.

Thanks in advance


Solution

  • 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