Find pixels per centimetre depending on screen sizes?
How could I find the number of pixels p开发者_JAVA百科er centimetre with respect to the physical screen size?
If you want to find the pixels per centimetre using just the logical densities (hdpi, mdpi, ldpi), then you may be out of luck. Those values are used by screens with different sizes.
However, using DisplayMetrics, you can instead use the physical pixels per inch and convert to centimetres.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
// Convert from dots per inch to dots per centimetre.
int xdpc = metrics.xdpi / 2.54;
int ydpc = metrics.ydpi / 2.54;
See here: http://developer.android.com/reference/android/util/DisplayMetrics.html
精彩评论