How to get the center coordinates of the screen in android?

前端 未结 1 835
借酒劲吻你
借酒劲吻你 2021-01-20 00:57

I am trying to get the x and y coordinates of the center of the screen. Here is what i tried:

Display display = getWindowManager().getDefaultDisplay();
final         


        
1条回答
  •  深忆病人
    2021-01-20 01:47

    I guess you're correctly getting the center coordinates, but setY is setting the position of the bottom edge of your ImageView. Off the top of my head, you may try something like

    SomeImageView.setY(height - SomeImageView.getDrawable().getIntrinsicHeight());
    

    0 讨论(0)
提交回复
热议问题