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?
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.
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 );
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.
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.
I think Android tries to find the "best match". So if 306 is in between 240 and 320, its much more closer to 320. So it will use xhdpi. You can read more here. Quoting from the official link to docs:
Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.
Related
I have to provide two different font sizes for two different types of devices. The first group are smaller devices (e.g. the Nexus S, or devices with around 480px height) and the second group are all other phones (e.g. Galaxy Nexus, Nexus 4, 5 and so on). I already supported tablets.
By now I created a values-sw320dp folder with a dimens.xml in it - for smaller devices to use, and there is also the default values folder with their dimens.xml in it, to support all other phones.
The problem is that the dimens.xml from the sw320dp folder is applied everywhere.
Am I supposed to create a values-sw340dp or values-sw360dp folder for those devices? What is the purpose of the dimens.xml in the default values folder if I am going to bucket devices by their smallest width? How does a device put itself in a density bucket, look for their closest sw-dp folder or what?
I know that this question has been asked a thousand times before, but I really could not google it out or find it on SO.
The Nexus S is a common hdpi device (240 dpi), with a resolution of 480x800 pixels.
Therefore, you can use the values-hdpi for storing that device's dimens .xml.
You might consider to support smaller devices such as mdpi or ldpi ones, as well.
And "not so smaller" devices too (i.e.: xhdpi and xxhdpi).
There are different types of qualifiers (IMHO), ones are responsible for density and the others are more about screen sizes, and there are some identifiers for tablets. It is not only having a single suffix like hdpi for folder, you can play with couple of them.
You can find more info on the Official website:
http://developer.android.com/guide/practices/screens_support.html
I tried to create an emulation of the Samsung Galaxy II i9100. All I really care about is screen size and pixel density. I created the following device definition:
And this virtual device:
But the emulated device looked like this:
Why was the resulting size 480x736? And the dpi value is slightly off.
ETA: here is what my app looks like:
And here is the output of ShowResources on an actual Samsung S2 i9100
First Galaxy S2 is HDPI, not TVDPI, also note that TVDPI is not a "primary density group" per Android documentation:
Resources for screens somewhere between mdpi and hdpi; approximately
213dpi. This is not considered a "primary" density group. It is mostly
intended for televisions and most apps shouldn't need it—providing
mdpi and hdpi resources is sufficient for most apps and the system
will scale them as appropriate. If you find it necessary to provide
tvdpi resources, you should size them at a factor of 1.33*mdpi. For
example, a 100px x 100px image for mdpi screens should be 133px x
133px for tvdpi.
source: http://developer.android.com/guide/practices/screens_support.html
On why the screen report 480x736, the 64 pixels is used by the system soft buttons (back, home, recent apps). To remove the soft buttons, you have to use/create a Device Definition that sets Buttons option to "Hardware", as exemplified below:
Alternative you can use Nexus S's Device Definition, it would have the correct buttons and DPI settings.
I'm about to adjust all drawables for an Android app for XXHDPI devices (like sony xperia Z and samsung s4). After thorough reading on Google's documentation, blogs, and SO, I'm confused as to the graphics I'm about to produce.
My concerns are the following:
Google states that I shouldn't worry about this density as it scales up XHDPI graphics - In the same manner, (before XXHDPI devices) why the production of XHDPI graphics was a necessity and it didn't scale up HDPI graphics?
Sony reminds developers not to exclude XXHDPI screens without clarifying if this concerns making adjustments to graphics - Do I have to redesign all graphic elements for XXHDPI?
Based on (2), Sony Xperia Z Ultra has 342dpi density but it is categorized as an XXHDPI device. - If I produce the graphics for an XXHDPI, which is twice the size of an HDPI density, the graphics will scale down by almost 1/3 to match Sony's density and this is undesirable. Why doesn't Xperia Z use the XHDPI drawables? What if I have a pattern and I can't afford any scaling since I'll lose the detail of the pixel-perfect pattern?
Are XXHDPI resources REALLY necessary?
I hope somebody can answer all the questions above.
EDIT
Below are the results of slightly scaling a graphic to adjust to various densities
- xhdpi image (1:1) no scaling
- xhdpi scaled up by 10%
- xhdpi scaled down by 10%
The detail loss is obvious at 2nd and 3rd image.
Unless you actually need your graphics to be "pixel perfect", scaling up from XHDPI will probably be fine for almost all cases. Pixels are so small the user won't be able to tell the difference. Do you actually have an XXHDPI device you can see your graphics on? You might have to provide XXHDPI resources for some drawables, just like you sometimes have to provide MDPI drawables when the HDPI ones don't scale down well.
"do not exclude" in this context means explicitly from the manifest. Some developers target densities in their manifest and that will affect the app not showing in the Play store, this is unrelated to actual graphics.
From that same page, it actually says that the density of that device is 440 dpi? - "One of the awesome features you’ll find in the recently announced Sony Xperia Z is its 5” screen, which boasts a display density of 440 dpi,"
XXHDPI resources are essential for stuff like icons on modern devices. Google will change their story and start to recommend them when they release their own XXHDPI Nexus device.
Think about it this way: xxhdpi devices are pretty much the STANDARD Android devices. Little chance Samsung & HTC are going to roll everything back to XHDPI just because Google can't keep up.
1) Android scales the drawables selecting the drawable that will produce the best result https://stackoverflow.com/a/14004691/936414
2) The post only asks you to include xxhdpi screen support in manifest. All XXHDPI devices take resources from XHDPI and scale them to fit accordingly. So no need of separate resources in XXHDPI folder
3) No need to include resources for XXHDPI.
So I got HTC smartphone with 800x480 display. I always thought that it is HDPI device. And I was ensured using the following code:
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
displayDensity = displayMetrics.densityDpi;
it says my device is 240dpi. But experimentally I'd discovered that android threats my device only as MDPI. Im sure bout this. I tested the same with another 800x480 (ZTE) and result was the same - it shows 240 in displayDensity but android threats it as MDPI device... But why is it so? On android.devepoler they said that 240dpi is HDPI. I'm totally confused. Why the heck 240 is threated as MDPI?
How I'd discovered that android treats my HTC as MDPI device:
In short what I made to ensure - I put a big image to drawable-hdpi (guessing AOS gonna use it) and smaller one to drawable-mdpi and than ran an app to see which it gonna use. And it always used image from drawable-mdpi instead of drawable-hdpi. To know how which image looks like on my device I ran app previously putting images to drawable folder of project.
However, like I mention above, I was guessing that my 800x480 HTC is HDPI due to code based on displayDensity but not on Configuration. Configuration says my device is Configuration.SCREENLAYOUT_SIZE_NORMAL and seems like thats the reason why AOS treats my device as MDPI only. So in conjunction with DisplayDensity of 240dpi (which must be HDPI instead of MDPI) it really frustrating. So now the question is why with Display density of 240dpi Configuration sets device to MDPI type? Whats the reason of this? I was thinking that the one and only way to detect the device type is its display density. And if it is 240dpi it must be HDPI device instead of MDPI.
You may try to read this page: http://developer.android.com/guide/topics/resources/providing-resources.html , it shows a complete explanation about screen density and others when you want to organize your resource folder.
About device being treated like MDPI it may be like Nexus 7, we were sure that it was MDPI, but it was using images from HDPI and also some values from MDPI/sw600dp (things that you will find better explained at that link above there), because its density, actually was TVDPI and so it's a 'middle' density between HDPI and MDPI. Try to download an app called ScreenInfo, on GooglePlay. It shows various informations about device screen, and may help you to make sure about your HTC.
Hope it helps.
Sorry for delay, so, first of all, you have to decide which public you want. You have to keep in mind that there are inumerous devices around there and it's almost impossible to cover all of them. I'd advise you to start with devices considered normal(screen normal, and MDPI density) because that is the baseline. And then, worry about others, based on that first one. Understand that the differentiation on resources folders are only done if necessary. In most cases, resources used to baseline works well for everyone.
Hope it helps.
hi guys i have been developing android app that should match most of the screen resolutions. And i just got struck at setting the drawable folder for this two resolution
1. 480 x 800 with approximate density of 217
2. 540 x 960 with approximate density of 240
And i have a different set of images for both the resolutions and i have set hdpi for 540 x 960 but don't have an idea of going about the 480x800 which also falls under hdpi. After goggling found a drawable qualifier called tvdpi which supports the appr. density of 213
When i set the tvdpi qualifier to the drawable folder i get "invalid resource directory name" error
Resolution and dpi are not directly related. It just so happens that many 800x480 devices are HDPI, then can just as easily be low dpi though if the screen is big enough.
If you really need direct resolution matching you will need to target API level 13 and use available width and height qualifiers for your resources or if you need to target a lower API level than 13, create your own resource loading scheme.
You can also use a combination of density and size qualifiers but that still leaves some room for two different resolutions falling into the same bucket.
But before you pick, you need to ask yourself do you really want the same pixel size for your drawables on a 3.7" 480x800 screen as you do for a 7" 480x800 screen.