1
I am developing an application where images and layouts adapt according to the logical density of the device.
You can get the screen dpi from the device through Java?
1
I am developing an application where images and layouts adapt according to the logical density of the device.
You can get the screen dpi from the device through Java?
0
It is possible to obtain the logical density through the code
getResources().getDisplayMetrics().density;
He will return you:
0.75 - ldpi (low resolution)
1.0 - mdpi (average resolution)
1.5 - hdpi (high resolution)
2.0 - xhdpi (great resolution)
3.0 - xxhdpi (+optimal resolution)
4.0 - xxxhdpi (excellent)
Browser other questions tagged java android
You are not signed in. Login or sign up in order to post.
"Screen pixel density" gives the impression that they are physical pixels, which is not the case. The term used in the documentation is "logical density". And a more precise way of saying it would be "The approximate relationship between a
dip
(Density-Independent pixel) and a physical pixel". Nor is it accurate because it only serves to group the densities in Buckets or groups (ldpi
,mdpi
,hdpi
, etc.). To obtain the exact density the calculation is more complicated.– Piovezan
Thanks @Piovezan, edited the reply.
– Machado