I am creating an android app and I want to be able to support as many android devices as possible that use Android 4.4 and above.
The screen sizes that I want to support are:
Normal
Large
xLarge
I have created different dimens.xml files for each size.
My first question is, the numbers that I put in each dimens.xml file should be based on the minimum dimension of each category?
For example: for normal I should design the layout in a device with dimension 470dp x 320dp, for large a device with dimensions 640dp x 480dp and for xlarge a device with dimensions 960dp x 720dp ?
My second questions is, let's say that we have our base dimension files for normal, large and xlarge, how many more dimension xml files should I create in order to support different densities too. Also do devices with Android 4.4 and above support all densities or are some excluded? (for example LDPI)
Now let's say that I exclude the LDPI density, should I make each density for each size or if I make one MDPI for each screen size and one HDPI for each screen size everything will "look" the way I want them, even in devices with XXXHDPI density?
One last thing, if you can recommend any devices to make my "base" layout that would be great.
hi you can handle size of different resolutions by this,
create different types of values folder.Create these folder inside res.
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
and dimens.xml create accordingly for different resolutions.Use all padding and margin from here.
This is way to handle different resolutions for different sizes.
for more info see the below .
for more details take a look from my project base structure
Thanks
Related
This is my first time working with multiple screens. I want to build my application for multiple screens i.e from sw320dp to sw720dp. I have created the following layout folders.
res/layout-sw320dp
res/layout-sw360dp
res/layout-sw480dp
res/layout-sw600dp
res/layout-sw720dp
I have copied all the xml files inside these folders. Is there anything else I need to add to make sure all the layouts support multiple screens. I have gone through the android documentation but I am not clear with the manifest.xml part. If anyone implemented multiple screen support in their application, so please do provide a description and implementation of the same.
Step 1 -You have to create different values folder for Different values for different screens.
Go to Your Project / app / src / main / res.
Right click on res and create different values folder in it.
Step - 2. Create folders named
values-large
values-small
values-sw320dp
values-sw320dp-hdpi
values-sw320dp-xhdpi
values-sw320dp-xxhdpi
values-sw480dp
values-sw600dp
values-sw720dp
Step - 3. Create dimensions.xml file in values folders.
Different values for different screen size.
values-ldpi 2.7" 240*320 ldpi
values-ldpi 3.3" 240*400 ldpi
values-ldpi 3.4" 240*432 ldpi
values-mdpi 3.2" 320*480 mdpi
values-hdpi 4.0" 480*800 hdpi
values-hdpi 3.7" 480*854 hdpi
values-xhdpi 4.7" 1280*720 xhdpi
values-xhdpi 4.65" 720*1280 xhdpi
values-sw480dp 5.1" 480*800 mdpi
values-sw480dp 5.4" 480*854 mdpi
values-sw600dp 7.0" tablet 1024*600 mdpi
values-sw720dp 10.1" tablet 1280*800 mdpi
when you attach dimension.xml file with your layout than you will get direct effect with your screen size.
This will help you to set dimensions for all type of screens.
There is a difference between supporting multiple screen sizes and creating different layout.xml files for each screen size.
In all the apps I've ever worked on, there were really only three different kinds of screens we cared about: small phones (years-old devices that our users weren't upgrading), "regular" phones (e.g. modern-day Samsung or LG phones etc), and tablets. Even considering those three kinds of screens, we often didn't need to create more than a single layout.xml file for a single screen.
If you have just one layout.xml file, it will display itself on any screen size. To "support" multiple screen sizes, you just need to make sure that your content looks good on short phones and tall phones, on wide phones and narrow phones, on phones and tablets, etc. This generally comes down to using dimensions like match_parent, or layout_weight to fill available space, etc.
It is only when you actually need to change what elements are on screen (as opposed to how big elements are) that you need to create extra layout.xml files. For instance, perhaps you know that a certain set of text + images just won't fit on smaller phones. Then you can create one res/layout/layout.xml that has only the text, and another res/layout-sw360dp/layout.xml that has the text + the image. Or maybe you have some content that you want to display side-by-side on a tablet, but you only want part of it on phones. Then you can make one res/layout/layout.xml with the normal content and one res/layout-sw600dp/layout.xml with the tablet-only content.
Regardless, when you decide that you do want to make multiple versions of a layout for different screen sizes, the only thing you have to do is create copies of your layout.xml in different layout-swXXXdp folders. Don't bother with layout-large unless your app supports really old API levels; the swXXXdp method is much more accurate and solves the same problem (but was only added in API 13).
Hey you dont need to do anything in manifest.
You have done the part with layouts.
Next you can do is to add support in drawable folder i.e. different density images for different sizes.
And if different screens require different values(dimentions etc) you need to create multiple file in values.
As i new in android development i just want to know is there any way to develop Android application for different screen sizes ?
help me.
Thank you in advance
Just add this in your project.
res/values/main.xml
res/values-sw600dp/main.xml -> 7+ inches
res/values-sw720dp/main.xml -> 10+ inches
Create this folder and just copy your xml file in all the folders.
Put your main.xml in those folders:
res/values/ //your default values (in your case for phones)
res/values-large/ //specfic values for relatively big screens
res/values-xlarge/ //specific values for really big screens
large: Screens that are of similar size to a medium-density VGA
screen. The minimum layout size for a large screen is approximately
480x640 dp units. Examples are VGA and WVGA medium density screens.
xlarge: Screens that are considerably larger than the traditional
medium-density HVGA screen. The minimum layout size for an xlarge
screen is approximately 720x960 dp units. In most cases, devices with
extra large screens would be too large to carry in a pocket and would
most likely be tablet-style devices. Added in API level 9.
see more infos here: http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes
Google provide good article how to support multiple screens
http://developer.android.com/guide/practices/screens_support.html
General advices:
use layout - for for mobile phone layouts
use layout-sw600dp folder for 7inch tablets layouts
use layout-sw720dp folder for 10inch tablets layouts
use dimens.xml in values folder to define dimentions for your UI
you also can use
values-sw600dp and values-sw720dp with its own dimens.xml file for 7 and 10 inch tablets
Writing apps for multiple devices requires one to have good knowledge on basic concepts like : what is Dpi, Screen density , Orientation etc.
Article below is good place to start for:
Supporting Multiple Screens
http://developer.android.com/guide/practices/screens_support.html
I am in the process of creating layouts for a new application and I am interested to know how you are usually approach this process.
Obviously it's a very general question, but I think we can get a lot of ideas from different developers' perspectives. As creating perfect layouts in Android, in my opinion, is one of the most difficult tasks in the app development process, I think the answers can be of value.
The assumption is that we want to support all device sizes with the least number of XML files, without compromising the application design quality.
In my case the designer of the app designed it with Galaxy S3 dimensions in mind (720 x 1280px).
Considering the 3:4:6:8 ratio -
What will be the base device you'll do the design for, so one layout file will look good on all normal size devices?
How would you handle the difference in device dimensions, thinking in dp -
Eg.
480 X 800 hdpi = 320 X 533dp
320 X 480 mdpi = 320 X 480dp
720 x 1280 xhdpi = 360 X 640dp
How will you still use the extra dp, so there won't be to many empty spaces, without making the layout not appropriate for 320 X 480 device?
When the designer marks a margin of 20px, how would you interpret it in the xml?
Taking into consideration he designed it on a 720 x 1280px canvas.
Start with some screen size as your base target device for e.g. 4.7 inch (hdpi) and create a single layout for default screens in layout folder and declare dimensions in dimens.xml in values folder.
Next, let's say you want your layouts for a 7" device, create values-sw320dp folder for 7" in portrait orientation and declare separate dimensions in dimens.xml in this folder.
Next, let's say you want your layouts for a 10" device, create values-sw720dp folder for 10" in portrait orientation and declare separate dimensions in dimens.xml in this folder.
PS: For landscape orientation, add -land in the end of folder names.
Next, let's say you have new devices such as xhdpi and xxhdpi devices, you can create values-xhdpi and values-xxhdpi folders.
Since you have defined dimensions in values folder, when you run the App, most of the dimensions will be used from here only. And you can add/update the dimensions in respective folders for screen-size and resolutions on which there is any mismatch.
Also, if you have got separate drawables for various size like mdpi, hdpi, etc you can place them under drawable-mdpi, drawable-hdpi, etc.
The Android system will take care of loading correct resources at run-time.
Note: On Android versions < 3.2, the folder naming was little different, you can refer that here.
Hope this helps.
Android automatically scales layouts to fit the current device. One way to make the solution more elegant would be to create separate folders drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi to hold the drawable resources - this is to make sure the same resource does not get used across all the different resolutions where it might not be so clear.
Do not use px (pixels) for measurements in the layout file - use dip (or density independent pixels) which allows to scale according to device pixel density.
The other extreme would be to have different layouts for different resolutions though this is is not advisable.
I am having the following specification images,
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Both in portrait and landscape. These are stretched in Tablet. But working fine in mobile. I am handling the configuration changes using the onConfigurationChanged() override method. Is any other way for giving the images for Android application. I reffered the following link for screen sizes. http://developer.android.com/guide/practices/screens_support.html
you can use drawable-large for tab
Following crocboy link is correct, and i suggest you to try including more buckets on your app. For example, in my applications i use also this:
drawable-sw600dp-mdpi
drawable-sw720dp-mdpi
In this buckets, put images that match tablets screen, for example in drawable-sw600dp-mdpi insert a background with this size 1280x800 and for drawable-sw720dp-mdpi a background with this size 1920x1200.
It's quite difficult to decide wich tablet to target, because we have different screen size.
EDIT
"application have to support all devices. So, the drawable folder images also have to support for all the devices. How to achieve this?".
Basically Android create this 4 folder for drawable:
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
(To be picky, low drawable-ldpi is not quite used, because small device are loosing appeal)But due to density and screen size you can have:
drawable-large-mdpi
drawable-large-hdpi
drawable-large-xhpdi
drawable-xlarge-hdpi
drawable-xlarge-mdpi
And so on with various combination! If you are looking for image perfection (like my graphics collegue, wich is an iOS psychopath) you have to create images for every type of screen, and put it on relative drawable bucket.
In the same link ("How to Support Multiple Screens"), they tell you how to create seperate drawable folders for each resolution - such as drawable-hdpi. When the system detects a high-resolution screen, it takes drawables from the high-density folders. You can also do the same with layout folders. If it's a low-resolution screen, it uses only images from the low-resolution images folder, drawable-ldpi. Here is also a good article article about how Android picks images from these folders.
I need to handle multiple XHDPI devices resolution. As far as i came to know, there are following Dimensions that are falling in XHDPI Range :
1184x768
1280x720
1280x800
1224x720
as they all belong to same Dimension, how to differentiate the Resources (drawables) it should load according to screen dimension?
or
If I use a single XHDPI layout and place their drawable in xhdpi folder is it sufficient or will this thing disturb the UI
Thank you
XHDPI is a single bucket
Short Answer:
A single layout for XHDPI will suffice with their resources placed in
the proper (xhdpi) drawables folder.
Long Answer:
Android Devices vary so much, so android decides that these set of screen resolutions fall under one bucket i.e. treated as one device since the variation among themselves is relatively lesser compared to the whole range. Android does runtime image manipulation to adjust your resources a little so that they function as expected.
Bonus:
To have finer control on images, look at the Scale attribute.
you can read more here
http://developer.android.com/guide/practices/screens_support.html
basically if you want...you can create folders with the following names:
layout-sw520dp-port //Galaxy Note at v4.0.3
layout-sw520dp-land layout-sw600dp-port // Nexus 7
layout-sw600dp-land layout-sw700dp-port
layout-sw700dp-land
etc. etc