Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find what density bucket the phone is in?

Slightly noob-ish question but I get confused when it comes to calculating what density bucket the phone falls in. I'll take my Galaxy S3 as an example.

It has a resolution of 1280 x 720 which means it has 306 dpi. Now, referring to the chart below, my phone falls in the hdpi category because it has more than 240 dpi but less than the 320 dpi needed to be an xhdpi screen. So, the phone is 853 x 480 DP (dividing by 1.5)

However, a screen information app on my phone tells me that it is an xhdpi screen. So, the phone is 640 x 360 DP (dividing by 2).

How do I know what correct density bucket my phone falls in?

enter image description here

Update:
I am trying to design my app for the top 10 Android phones in my country. So I am calculating their sizes in DPs to design UIs based on their "smallest width DPs". This isn't a one-off size calculation.

like image 350
An SO User Avatar asked Jan 30 '15 16:01

An SO User


2 Answers

If you want to know it once, you can get an app like ScreenInfo and run it. If you want to know programmatically, you can add density folders, such as values-mdpi and values-xhdpi, place an xml file in it, say whoami.xml with the following content:

<resources>
    <string name="density_bucket">mdpi</string>
</resources>

And, respectively:

<resources>
    <string name="density_bucket">xhdpi</string>
</resources>

and then inquire from the app:

String densityBucket = getResources().getString( R.string.density_bucket );
like image 173
323go Avatar answered Oct 22 '22 03:10

323go


Hey I recognize that chart! Mostly because I created it :D. To clarify, the chart shows what dpi each density bucket is baselined to, but cannot be used to determine which density bucket a device should be classified as. That said, this illustration below shows how devices are generalized into density buckets, and you can see they may have a higher or lower dpi than the bucket they fall in.

Density bucket generalization

Now to answer your question, unfortunately, there is no guaranteed way to know what density bucket a device will fall into purely based off of its specs. This is because the device manufacturer is able to choose the density bucket. Most of the time, they will choose the bucket closest to the actual dpi of the device**. Luckily, Google has gathered a list of common devices, along with their screen dimensions in dp, and density buckets. This should give you an idea of how to properly support the most prevalent screen size that are out in the wild.

**Note: Some devices have their own special density buckets. Most notably, the Nexus 7 (2012) is 213dpi (tvdpi), the Nexus 5X is 420dpi, and the Nexus 6 and 6P are 560dpi. These devices grab assets from the other density versions and scale them.

like image 39
Steven Byle Avatar answered Oct 22 '22 04:10

Steven Byle