获取手机屏幕的中心坐标

1Qu*_*ion 8 java android coordinates

有人能举例说明如何获得当前显示屏幕的中心坐标吗?我希望我的对象始终相对于活动视图的中心坐标.

Dev*_*ath 10

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

int mWidth= this.getResources().getDisplayMetrics().widthPixels;
int mHeight= this.getResources().getDisplayMetrics().heightPixels;
Run Code Online (Sandbox Code Playgroud)