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

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

    if you wish to align a view at the center of other view then you can use this -

    float center_x = parent_view.getX() + parent_view.getWidth()/2 - child_view.getWidth()/2;
    

    and then obviously using -

    child_view.setX(center_x);
    

提交回复
热议问题