gpt4 book ai didi

android - 如何在android中获取屏幕的中心坐标?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:09 24 4
gpt4 key购买 nike

我正在尝试获取屏幕中心的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com