问题
Samsung galaxy 10 inch tablet spec is saying that its display density is 149 PPI.
But when I printed dpi using display metrics its showing as 160 dpi.
how to know the exact dpi of an devices.
回答1:
PPI and DPI is two different things. The important thing to know about when developing Android applications is the DPI.
It can be found like this:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int dpi = dm.densityDpi;
Android works with general classes of DPI:
- ldpi = 120
- mdpi = 160
- hdpi = 240
- xhdpi = 320
Take a look here for more information: http://developer.android.com/guide/practices/screens_support.html
回答2:
Adding to Cant0na answer, which is totally correct, in this great post Dianne Hackborn (Google engineer) explains exactly how the dpi works. I think the reading of it is a must for every Android dev. Among other things, she says:
So Android defines a few major buckets of density values that devices can used, called ldpi (approx 120dpi), mdpi (160 dpi), hdpi (240 dpi), and xhdpi (320 dpi). Manufacturers can select the density that is appropriate for their device, as long as it results in a screen that (after scaling for density) is within the minimum allowed screen size of the platform.
来源:https://stackoverflow.com/questions/9224428/10-inch-tablet-with-149-ppi-is-showing-as-160-dpi-in-program