Android - standard layout folder, which screen size? - android

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

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 layout for 5 and 4 inch Android devices

I have an Android application with one layout file. I have different layout files for different densities, i.e., layout-hdpi, layout-mdpi, etc. I also have different dimens files in corresponding value directories (values-mdpi, values-hdpi, etc).
My problem is that I would like to use different layouts for 4 and 5 inch screen devices. I am testing on two physical a 4 inch and a 5 inch and both devices use the layout from the /res/layout folder and the dimens file from the /res/values-hdpi/ folder (in other words, they use the same resources).
Is there a way to make the 4 inch device use a different dimens.xml file - if not automatically, can this be done programmatically?
You can use something like layout-sw320dp or similar. This will differentiate layouts based on minimum display width.
Here is much more about it:
https://developer.android.com/guide/practices/screens_support.html#NewQualifiers
Density is not related to size, they tell you how many pixels there are in on square inch of screen, not how may inches of space there are in the screen. you should use size related resources. for example layout-w500dp folder would be used for screens that have at least 500dp of width.this should help

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.

How can I fix android tablet's width and height

I am making android application in tablet using fragments so that I arranged 8 buttons vertically in 10.1 tablet it is showing fine but in 7.1 tablet only 5 icons it is showing.
So How can I manage height and width properly in all tablets ... please help
Remember to write different xml layouts (with same name) and place to different folders: layout-large, layout-normal, layout-small and layout-xlarge. Same is with drawables (different size images) and values (different type padding and other values). These folders are for different phone/tablet types with various resolution and screen size. If you do it, then you can easily manage layout for small device and not touch big screen devices. Device is picking xml file automatically so it's good practice to place xml files in different folders for various phones.
More information you can find in http://developer.android.com/guide/practices/screens_support.html
You can use different layout for different screen sizes. You can also add different buttons and other drawable also. Please see the link
Supporting Multiple Screens
You can write different xml layouts using different folders:
For example:
res/layout
res/layout-sw600dp //used by 7''
res/layout-sw720dp //used by 10''
Also you can use the same layout with the same component but with different dimensions.
You can use #dimen/my_dimen notation, and then put your my_dimen in different folders like:
res/values/dimens.xml
res/values-sw600dp/dimens.xml
and so on..
Official doc: http://developer.android.com/guide/practices/screens_support.html

Providing layout resources for specific screen sizes

In my Eclipse project I currently have the following folders:
layout-land
layout-large-land
layout-sw600dp-land
layout-xhdpi-land
(I have others too, but the problem right now is for landscape layouts only.)
My layout is quite specific: it varies greatly when I change the size of the screen in Graphical Layout in Eclipse.
From what I have learned from Android docs and from AVD setup, normal screens are from 3.6" to 4.9". Large are from 5.0" to 7.4". Small are up to 3.5".
I go to my xml layout file in the layout-land folder. The screen size chosen already is 4.0", which is all good, because we're in the landscape layout folder for normal screen sizes. I now choose a screen size of 5.1". The editor opens the xml file in the layout-large-land folder -- also OK.
I now choose this screen: 4.65" (720x1280 xhdpi). The size of 4.65" is still in the normal range, and the editor uses the xml file in the layout-land folder. This should be ok, except the fact that my layout changes greatly! I thought that maybe this is because of xhdpi, and that's why I created the folder above (number 4), but that does not seem to work with Eclipse (the xml file is not used for this screen). Same problem occurs with 4.7".
So what my question really is:
How can I provide different xml layouts for screens in the normal range?
Note that there Android platform doesnt consider the screen sizes as much as the dp or Density Pixels. Also there are several of known issues with Eclipse and ADB Plugin for eclipse. The best way to test is with the actual device. For the information to support the screens, we just have to place the files in folders below and it will possibly work for most of the devices with the specified DP.
layout-land
layout-large-land
layout-sw600dp-land
layout-xhdpi-land
http://developer.android.com/guide/practices/screens_support.html

Categories

Resources