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

前端 未结 5 1754
温柔的废话
温柔的废话 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:22

    As @aiueoH mentioned, you can use getPivotX() and getPivotY().

    Try using this for finding coordinates of centre:

    int centreX = view.getPivotX()/2;
    int centreY = view.getPivotY()/2;
    

提交回复
热议问题