获取手机屏幕的中心坐标

获取手机屏幕的中心坐标

问题描述:

有人可以给我一个例子,说明如何获取当前显示屏幕的中心坐标吗?我希望我的对象始终相对于活动视图的中心坐标。

Can someone give me an example of how to get the center coordinates of the current displayed screen? I would like my objects to always be relative to the center coordinates of the active view.

您可以尝试使用 DisplayMetrics 实现解决方案



You can try with DisplayMetrics to achieve your solution

int mWidth= this.getResources().getDisplayMetrics().widthPixels;
int mHeight= this.getResources().getDisplayMetrics().heightPixels;