Android杂谈之获取屏幕宽高像素

方法一: (可在View中获取屏幕像素)
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
int width1 = dm.widthPixels;
int height1= dm.heightPixels;
方法二:(需要在Activity中获取)
WindowManager manager = this.getWindowManager();
DisplayMetrics displayMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(displayMetrics );
int width2 = displayMetrics .widthPixels;
int height2 = displayMetrics .heightPixels;

你可能感兴趣的:(Android杂谈之获取屏幕宽高像素)