Android Studio multiple screen size - android

I'm developing an app for android devices, but i have some problems with the variety of screen sizes and different densities. So I see that before android 3.2 the solution was to create 4 folders: Small, Medium, Large and xlarge, now this method is deprecated. The problem is though running the application in similar devices the layout looks different. Which and how much folders should i do?

This is what I did for supporting all screen sizes, it can be a lot of work:
Directories:
layout-sw320dp
layout-sw320dp-land (smallest phones, 3.7" and smaller)
layout-sw360dp
layout-sw360dp-land (approximately 4-4.7")
layout-sw400dp
layout-sw400dp-land (most phones right now, 5-6")
layout-sw600dp
layout-sw600dp-land (7-8" tablets)
layout-sw720dp
layout-sw720dp-land (9" tablets)
layout-sw800dp
layout-sw800dp-land (10" tablets)
The same applies to directory names for drawables:
drawable-sw320dp
drawable-sw320dp-land
etc etc .. that's the general idea
Google's docs mentions sw720dp for 10" tablets but if you want separate layouts for 9" and 10" I discovered sw720dp is 9" and sw800dp is 10"

Use the new Layout Aliases like this :
res/layout/main.xml: single-pane layout
res/layout-large: multi-pane layout
res/layout-sw600dp: multi-pane layout
But i think the most importing thing to adopt your layout to different screen sizes is to follow best practices for User Interface ( when to use wrap_content, match_parent RelativeLayout, LineareLayout, Qualifiers ... )
Here's a good tutorail to start with Supporting Different Screen Sizes

Related

Android : Screen Size

I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.

Different layouts for different screen density

I'm trying to figure out how to define different layout for different screen density.
At the moment I have to manage a 7" (Nexus 7), 10" (galaxy tab S) and now a 9.7" (Galaxy tab A) tablets
So I've defined for now two layouts directories :
layout (for 7")
layout-sw720dp (should be only for 10")
My problem is the 9.7" tablet match the layout-sw720dp directory as my 10" tablet. So from this point I don't know how to define another layout directory based only on my 9.7" tablet.
The density of the 10" is 288ppi and the density of the 9.7" is 132ppi.
I guess if the density would be the same I wouldn't have this problem.
Is it possible to create a new directory layout based only on the density ? What is the best practice for this use case and manage at the same time my 10" layout and my 9.7" layout with a different density ?
you have two options for this either you use
layout-sw600dp
layout-sw720dp
layout-sw800dp
or use the dpi wise folder structure like this
drawable-land-mdpi
drawable-land-hdpi
drawable-land-xhdpi
drawable-land-xxhdpi
What I've done is instead of using layout-sw720dp I used these two layouts:
layout-hpdi for 10" with hight dpi
layout-mdpi for 9.7 with medium dpi
And it seems to work good.
Edit
Actually I kept layout-sw720dp and then I use also a value-hdpi and value-mdpi resource directories to manage at the same time screen size and density.

What is difference between layout-small and layout-sw320dp

I know how to use the following folders but for example I do not know what is difference between layout-small and layout-sw320dp?
Also, Suggest for me that which the folders are important to optimization.I do not like my program be seen for users as irregular.I want a final answer from you.
Based on which the folders I design my layouts? Because I have not multiple android devices to test the layout in different screen size.
I know how to use the folders and I have not problem about it.but my question is which the folders for continuous use and for all devices?
layout-sw320dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
layout-small,
layout-large etc...
Both are qualifiers to define layouts for specific screen sizes.
Before Honeycomb - 3.0 (I guess), the screen's diagonal size was measured based in 4 groups: small, normal, large, and extra-large.
After that layout resources are defined for screen sizes with the smallest width (sw stands for smallest width).
Resuming, layout-small is deprecated and layout-swXXXdp qualifier should be used instead.
You can get more info about these qualifiers in Supporting Multiple Screen's Android official doc page.
The difference is that the qualifiers -small, -normal, -large had been marked as deprecated in API 13. Now the recommended way to go is using the -swdp folder structure. (see http://developer.android.com/guide/practices/screens_support.html#support )
The number of resources folders in your project depends basically on the type of devices you're targeting at (small phones, phablets, tablets, ...) and the number of different layouts you want to maintain. In most cases implementing a layout for landscape/portrait modes for phones and for tablets should be enough. Though you can create another layout for a specific screen size if you really need it.
Hope this helps.

Android application for different screen sizes

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

Android - standard layout folder, which screen size?

I'm implementing an application and I want to support all screen sizes. I have 4 layout folders: layout, layout-small, layout-large and layout-xlarge.
Which screen size supports the standard layout folder? Is it even necessary?
Which screen size supports the standard layout folder?
In your case, it will depend on what files are in what directories.
Let's say that you have main.xml in layout/, and not in any of the other three candidates. Then, setContentView(R.layout.main) will use the copy in layout/.
Now, let's say that you add a revised version of main.xml in layout-xlarge/. On an -xlarge device, Android will use the layout-xlarge/ version of main.xml, and on other screen sizes, Android will use the layout/ version of main.xml.
Now, let's say that you add a third main.xml version, this time in layout-small/. Android will still use the layout-xlarge/ copy of main.xml for -xlarge devices. However, all other devices will use layout-small/, and the layout/ copy of main.xml will be ignored. Android will not try to shrink a layout from a larger size (e.g., -xlarge layout on a -normal device), but it will try to expand a layout from a smaller size (e.g., a -small layout on a -normal device).
What I tend to do is use layout/ for:
Layouts that do not need different versions for different sizes
Layouts to be used on -normal devices (as I rarely support -small)
I then use layout-large/, layout-xlarge/, or their Android 3.1+ replacements (e.g., layout-w720dp/) for layouts to be used on larger screen sizes.
However, that is just my particular style, and you are welcome to do what you want, within the usage rules described above.
using modern notation is a better solution:
/layout // for phones
/layout-sw600dp // for 7 inch tablets
/layout-sw720dp // for 10 inch tablets
In popular:
Mdpi screen smartphone is cheap
Hdpi screen smartphone is expensive.
If you use layouts only mdpi folder, this layout will be used for all screens
Legend:
layout-small = ldpi
layout = mdpi
layout-large = hdpi
layout-xlarge = xhdpi

Categories

Resources