我正在尝试获取屏幕中心的 x 和 y 坐标。这是我尝试过的:
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
但这不起作用,当我说:
SomeImageView.setY(centerY);
我没有在屏幕中央看到它。谁能帮我解决这个问题?
谢谢
最佳答案
我猜你得到的中心坐标是正确的,但是 setY
正在设置你的 ImageView
的底部边缘的位置。在我的脑海中,你可以尝试类似的东西
SomeImageView.setY(height - SomeImageView.getDrawable().getIntrinsicHeight());
关于android - 如何在android中获取屏幕的中心坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18304460/