Android笔记:获取屏幕信息
像素密度(dpi)
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
Log.d("MainActivity", "xdpi is " + xdpi);
Log.d("MainActivity", "ydpi is " + ydpi);
屏幕长宽(px)
float xpx = getResources().getDisplayMetrics().widthPixels;
float ypx = getResources().getDisplayMetrics().heightPixels;
Log.d("MainActivity", "xpx is " + xpx);
Log.d("MainActivity", "ypx is " + ypx);
在像素密度为160dpi的设备上1dp=1px,
在像素密度为320dpi的设备上1dp=2px.