获取Android 屏幕的宽和高
程序员文章站
2022-05-04 23:40:37
...
获取屏幕宽和高的两个方法
方法1:
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
int width = dm.widthPixels;
int height = dm.heightPixels;
Log.d("lisc", width + " , " + height);
方法2:
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
int height = outMetrics.heightPixels;
Log.d("lisc", width + " , " + height);
上一篇: PHP最长单一子串