When supporting different screen sizes (densities) in Android often the focus is on creating different layouts for every possible screen. I.E.
- ldpi
- mdpi
- hdpi
- xhdpi
- xxhdpi
- xxxhdpi
I designed a layout for an xhdpi screen as a reference, and defined it's dimensions in dimens.xml. Now I want to give support it to every possible screen size. How can I do that?
As far as I know, I can use this tool to figure out the proper dimens.xml for other screen sizes and add it to my project. Is this the right way to do it in my situation?
Another question, do I only need to create dimens.xml for above screen dimensions? If yes then what is w820dp
?
Thanks for your help. I need to support phones only (not tablets or other devices).
we want to see the changes of required view size in different screens.
We need to create a different values folders for different screens and put dimens.xml file based on screen densities.
I have taken one TextView and observed the changes when i changed dimens.xml in different values folders.
Please follow the process
normal - xhdpi \ dimens.xml
The below devices can change the sizes of screens when we change the normal - xhdpi \ dimens.xml
nexus 5X ( 5.2" * 1080 * 1920 : 420dpi )
nexus 6P ( 5.7" * 1440 * 2560 : 560dpi)
nexus 6 ( 6.0" * 1440 * 2560 : 560dpi)
nexus 5 (5.0", 1080 1920 : xxhdpi)
nexus 4 (4.7", 768 * 1280 : xhdpi)
Galaxy nexus (4.7", 720 * 1280 : xhdpi)
4.65" 720p ( 720 * 1280 : xhdpi )
4.7" WXGA ( 1280 * 720 : Xhdpi )
Xlarge - xhdpi \ dimens.xml
The below devices can change the sizes of screens when we change the Xlarge - xhdpi \ dimens.xml
nexus 9 ( 8.9", 2048 * 1556 : xhdpi)
nexus 10 (10.1", 2560 * 1600 : xhdpi)
large - xhdpi \ dimens.xml
The below devices can change the sizes of screens when we change the large - xhdpi \ dimens.xml
nexus 7 ( 7.0", 1200 * 1920: xhdpi)
nexus 7 (2012) (7.0", 800 * 1280 : tvdpi)
The below screens are visible in " Search Generic Phones and Tablets "
large - mdpi \ dimens.xml
The below devices can change the sizes of screens when we change the large - mdpi \ dimens.xml
5.1" WVGA ( 480 * 800 : mdpi )
5.4" FWVGA ( 480 * 854 : mdpi )
7.0" WSVGA (Tablet) ( 1024 * 600 : mdpi )
normal - hdpi \ dimens.xml
The below devices can change the sizes of screens when we change the normal - hdpi \ dimens.xml
nexus s ( 4.0", 480 * 800 : hdpi )
nexus one ( 3.7", 480 * 800: hdpi)
small - ldpi \ dimens.xml
The below devices can change the sizes of screens when we change the small - ldpi \ dimens.xml
2.7" QVGA Slider ( 240 * 320 : ldpi )
2.7" QVGA ( 240 * 320 : ldpi )
xlarge - mdpi \ dimens.xml
The below devices can change the sizes of screens when we change the xlarge - mdpi \ dimens.xml
10.1" WXGA ( tABLET) ( 1280 * 800 : MDPI )
normal - ldpi \ dimens.xml
The below devices can change the sizes of screens when we change the normal - ldpi \ dimens.xml
3.3" WQVGA ( 240 * 400 : LDPI )
3.4" WQVGA ( 240 * 432 : LDPI )
normal - hdpi \ dimens.xml
The below devices can change the sizes of screens when we change the normal - hdpi \ dimens.xml
4.0" WVGA ( 480 * 800 : hdpi )
3.7" WVGA ( 480 * 800 : hdpi )
3.7" FWVGA Slider ( 480 * 854 : hdpi )
normal - mdpi \ dimens.xml
The below devices can change the sizes of screens when we change the normal - mdpi \ dimens.xml
3.2" HVGA Slider ( ADP1 ) ( 320 * 480 : MDPI )
3.2" QVGA ( ADP2 ) ( 320 * 480 : MDPI )
You can put
dimens.xml
in1) values
2) values-hdpi
3) values-xhdpi
4) values-xxhdpi
And give different sizes in
dimens.xml
within corresponding folders according to densities.You have to create Different values folder for different screens . Like
For more information you may visit here
Edited By @humblerookie
You can make use of Android Studio plugin called Dimenify to auto generate dimension values for other pixel buckets based on custom scale factors. Its still in beta, be sure to notify any issues/suggestions you come across to the developer.
I've uploaded a simple java program which takes your project location and the dimension file you want as input. Based on that, it would output the corresponding dimension file in the console. Here's the link to it:
https://github.com/akeshwar/Dimens-for-different-screens-in-Android/blob/master/Main.java
Here's the full code for the reference:
Android 3.2 introduces a new approach to screen sizes,the numbers describing the screen size are all in “dp” units.Mostly we can use
smallest width dp: the smallest width available for application layout in “dp” units; this is the smallest width dp that you will ever encounter in any rotation of the display.
To create one right click on res >>> new >>> Android resource directory
From Available qualifiers window move Smallest Screen Width to Chosen qualifiers
In Screen width window just write the "dp" value starting from you would like Android Studio to use that dimens.
Than change to Project view,right click on your new created resource directory
new >>> Values resource file enter a new file name dimens.xml and you are done.
In case you want to view more: Here's a link for a list of devices (tablet, mobile, watches), including
watch
,chromebook
,windows
andmac
. Here you can find the density, dimensions, and etc. Just based it in here, it's a good resource if your using an emulator too.If you click a specific item, it will show more details in the right side.
Since it's
Android
, I will post related to it.~ It's better if you save a copy of the web. To view it offline.