Get Android Phone Display Density and Ratio
This post about how to get display density for different type of android phone.
Android have different kind of device resolution based on the resolution we need an image
See the Below example Different resolution ratio.
This post about how to get display density for different type of android phone.
Android have different kind of device resolution based on the resolution we need an image
See the Below example Different resolution ratio.
ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3
xxxhdpi = 1:4
For example
mdpi (320*1)*(50*1) = 320 *50(1 : 1)
ldpi (320*0.75)*(50*0.75) = 240 *
37.5(1 : 0.75)
hdpi (320*1.5)*(50*1.5) = 480 *75 (1:1.5)
xhdpi (320*2)*(50*2) = 640
* 100(1:2)
xxhdpi (320*3)*(50*3) = 960
* 150(1:3)
get Device Display Density
private void checkDeviceDensity(){
int dpiDensity =
getResources().getDisplayMetrics().densityDpi;
switch(dpiDensity){
case DisplayMetrics.DENSITY_LOW:
Log.e("sdk", "::::DENSITY_LOW::::");
//Do sth for LDPI-screen devices
break;
case DisplayMetrics.DENSITY_MEDIUM:
//Do sth for MDPI-screen devices
Log.e("sdk", "::::DENSITY_MEDIUM::::" +adwidth +adheight);
break;
case DisplayMetrics.DENSITY_HIGH:
//Do sth for HDPI-screen devices
Log.e("sdk", "::::DENSITY_HIGH::::");
break;
case DisplayMetrics.DENSITY_XHIGH:
//Do sth for XHDPI-screen devices
Log.e("sdk", "::::DENSITY_XHIGH::::");
break;
case DisplayMetrics.DENSITY_XXHIGH:
//Do sth for XHDPI-screen devices
Log.e("sdk", "::::DENSITY_XXHIGH::::");
break;
case DisplayMetrics.DENSITY_XXXHIGH:
//Do sth for XHDPI-screen devices
Log.e("sdk", "::::DENSITY_XXXHIGH::::");
break;
}
}
No comments:
Post a Comment