Wednesday, February 5, 2014

Get android device resolution problem, experts for advice


            
Question: How to get the actual resolution of the device?

 DisplayMetrics dm = new DisplayMetrics (); 
android.view.Display display = getWindowManager () getDefaultDisplay ();.
display.getMetrics (dm);


1:800 * 480 2.3.3 simulator test results: density: 1.5, densityDpi: 240, widthPixels: 533, heightPixels: 320, so it seems right, 533 * 1.5 = 800
2:800 * 480 4.0.3 simulator test results: density: 1.0, densityDpi: 160, widthPixels: 533, heightPixels: 320, this is not right, density should still 1.5 fishes
Test 3:1280 * 720 4.1 real machine results: density: 1.0, densityDpi: 160, widthPixels: 640, heightPixels: 360, this is not right, density should be 2.0 fishes
2.3.3 Test 4:854 * 480 real machine results: density: 1.5, densityDpi: 240, widthPixels: 569, heightPixels: 320, this is right

Values ​​above 2.3 are not right, the way to get it changed?

I then discovered trace breakpoints dm there noncompatDensity, noncompatWidthPixels, noncompatHeightPixels etc., these values ​​no matter what system version, what resolution, values ​​are correct (eg 1280 * 720 which three values ​​are 2.0,1280 , 720), but these attributes are beginning noncompat can not directly access
Reply:
No beginning noncompat properties in 2.3.3 version
Reply:
densityDpi (number of pixels on a line span inch units) is calculated according to the actual size and resolution of the LCD screen. The same is the 800x480 resolution, 4.0.3 and 4.1 of the machine will be larger than the size of 2.3.3.

No comments:

Post a Comment