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.
Related
I need to adjust my GUI to multiple devices and check how my app looks on them. Many of the I don't have. How can I know device density (hdpi, xhdpi... etc.) on specific device without looking for each device on the web. I have this table: http://www.emirweb.com/ScreenDeviceStatistics.php but its not complete. Is there fast way to getting this information?
IMO You are not adopting the right approach to screen sizes. To be sure that all devices will be supported, you should add all your images in the corresponding folders mdpi, hdpi xhdpi and so on, and not the other way round(Adding image by devices). Android is intelligent enough to detect the devices density and display the right format. Let's say you run your app on an xxhdpi device, and you don't have an image that corresponds to it, Android is intelligent enough to choose an image from the closest folder to xxhdpi, it could be xxxhdpi or xhdpi.
Take a look at:
http://developer.android.com/reference/android/util/DisplayMetrics.html
and here:
How to get screen display metrics in application class
However if you want to adjust your layout to specific devices I strongly suggest reading this stuff:
http://developer.android.com/guide/practices/screens_support.html
Galaxy s4
Screen: 4.99", 1920x1080 (FullHD).
Which the res folder would be used in FHD and what's the dpi value should be set?
xhdpi or xxhdpi? And how can I calculate it?
I didn't find any info in the developer docs and in the screens_support article
It's 441 dpi, isn't it? So almost certainly xxhdpi, which is already supported in the Android framework. But why worry about it at this time? Assuming you're already supporting xhdpi, the likelihood that the average user can detect the different between xhdpi and xxhdpi assets is becoming increasingly small.
-- Edit --
Actually, I'd say it's certain to be xxhdpi, given that this is already in use with the new HTC One (which is at 468dpi).
As Sony Xperia U's resolution is 480 * 854 (280ppi) it should take images from high density folder(drawable-hdpi) but its taking images from extra high folder(drawable-xhdpi) and not scaling properly.We are not having actual device for testing so setting emulator Height=854 ,Width=480 and density=320.We have also added specific drawable-h854dp folder for xperia but it is still taking images from drawable-xhdpi and not scaling it.Has any one faced this kind of issue?Suggest us if have any ideas.
Thanks in advance!!
280ppi is directly between hdpi (240ppi) and xhdpi (320). Chances are, Sony has defined the Xperia U as an xhdpi device, so for it to take resources from drawable-xhdpi is completely normal. There's an app in the market I found called Check Screen Size that will tell you what density your device is defined as (and what resources it will be using).
If you put it under drawable-w240dp or drawable-h427dp or even drawable-w240dp-h427dp it should work.
I wouldn't bother too much since it's Sony's fault that they have not followed Android device guidelines for minimum (effective) screen size.
What simulator resolution i should keep when developing application for Samsung galaxy s2 and galaxy s3 ?
What i found that samsung galaxy s2 has 480x800 resolution and s3 has 1280x720 resolution so what i have understood up till now that I should ask my graphics designer to provide me hdpi graphics that contain 480x800 background images and to implement same background image in galaxy s3 mobile, I will use image of size 1280x720 and put in xhdpi folder so that it can work on s3.
The background image is something which covers whole available area for mobile app. so am i right ??
You will need to create several emulators or get various devices.
There are some pretty important ones, so generally you need to make sure you have:
ldpi, mdpi, hdpi, xhdpi
and
small, medium, large, xlarge
Some people choose to exclude certain sizes (like small and ldpi) but htat's up to you,
if you go with some or all of the following, it should be a good start:
480x320 (SE Mini 10), 480x800 (GS2, Desire, etc), 1280x720 (GS3, Galaxy Nexus etc), 1280x800 (Note, Xoom, various other tablets)
HTC ChaCha (because it's landscape default)
You need to make sure you create resources in the relevant folders for each density, usually, I tend to ignore ldpi and just put resources in:
mdpi,hdpi and xhdpi (mdpi will be scaled down for ldpi devices,
automatically)
You may also need to create various portrait and landscape layouts in different sizes.
Reading this page provides most of the necessary information:
http://developer.android.com/guide/practices/screens_support.html
This page also contains important information regarding size distribution and popularity that is constantly up to date:
Android Stats
One thing that Android does for you is that it manages resolution. If you use the proper size formats (dp, sp, etc), your layout will scale to almost all resolutions. If you place images in the proper drawable folders (hdpi, ldpi, mdpi, etc), the OS will also swap those out as necessary.
Also, the emulator should handle resolutions for specific devices, if I recall correctly.
Desing lazout in smart way! Usualy it means don't put to mutch content in one layout.
Make sure that evrything looks good on smallest size and bigest size. It is better to treat tablets separetly. Read how providing alternative resources works, you can build sepereate layouts for each screen size.
Check if the hardware is available on that device before using it. hasSystemFeature() can be used for checking.
As per managing resources(images) in > Android 1.6 version, we need to keep different-resolutions image in Drawable-Hdpi, Drawable-Mdpi, Drawable-Lpi folder particularly.
And as per this page: http://developer.android.com/guide/practices/screens_support.html ,
In Low density section - there are three resolutions used: 240*320 , 240x400 , 240x432 for the Small screen, Normal Screen, Large Screen particularly.
same way for Medium density section - there are three resolutions used: 320x480 , 480x800 , 480x854 for the Small screen, Normal Screen, Large Screen particularly.
and same way for High density ........
but i am confused here:
(1) How do i come to know that whether small, Normal or Large screen is used, i mean is there any way to know ?
(2) How do i come to know which type of density i am using ?
(3) And in Drawable-Hdpi, Drawable-Mdpi, Drawable-ldpi folder, which resolution's image we should keep particularly?
There are specific Android API calls that can, at runtime tell you what density and (small/large/normal) screen size a handset has. However, as a developer we should not need to worry about individual handsets at all. All we need to do is to have ldpi/mdpi/hdpi assets and small/normal/large layouts in the apk. Android internally handles everything.
Dont forget to get an indepth understanding of how Android determines which assets to use and aliasing here.
Why do you want to know the actual density? It's Android's business. But I'm sure there is a way to retrieve this information.
For development I put everything in the hdpi-folder. I also could put everything in a general Drawable Folder.
At the time u publish u can decide if u want to provide already downscaled resources for ldpi and mdpi. However, thats not necessary.
Update: Retrieve actual density with this class and best practices
Update 2: I found a 25 min video from Motorola discussing all those issues: Working with multiple screens
1) Change the content of the layout in different folders i.e layout-small, layout-large, etc Now test it in Different emulator with different screen resolution.
2) For Finding out density of the Device use
Log.d("Density", "" + (getResources().getDisplayMetrics().density));