方法一: (可在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;
网友评论