获取android屏幕分辨率

deprecated

Display dp=getWindowManager().getDefaultDisplay();
int height=dp.getHeight(); 
int width=dp.getWidth(); 

instead method(推荐)

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

有虚拟按键的手机获取屏幕分辨率会不正确,只需要将
display.getSize(size)改成display.getRealSize(size),就能获得正确的屏幕分辨率

other method

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width  = metrics.widthPixels;

你可能感兴趣的:(android开发)