如何在Android中获取屏幕的中心坐标? [英] How to get the center coordinates of the screen in android?
本文介绍了如何在Android中获取屏幕的中心坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取屏幕中心的x和y坐标.这是我尝试过的:
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 Point size = new Point();
display.getSize(size);
height = size.y;
float centerY=height/2;//i expect this is the y coordinate of center
但是当我说:这不起作用
But this does not work, when i say:
SomeImageView.setY(centerY);
我在屏幕中央看不到它.有人可以帮我吗?
I do not see it at the center of the screen. Can anyone help me with this?
谢谢
推荐答案
我想您已经正确获取了中心坐标,但是 setY
设置了底部边缘的位置ImageView
.在我头顶上方,您可以尝试类似
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());
这篇关于如何在Android中获取屏幕的中心坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文