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
Related
So I'm creating different xml files for different phone screens in Android Studio.
I tried a number of methods for creating xml for different screens.
The first one was 4 folders layout-small, large, normal and xlarge it worked for the big tablet screens except for Nexus one of size 480 x 800.
so I created a folder called layout-w320dp and it worked but it overrided my large and xlarge xml files.
As in when ever I click for tablet screens it brings up the w320dp xml file instead of the xml in large and xlarge folders.
So I created the other folders w480dp, w600dp, w720dp but using xml files messes up everything but if I don't use a xml from these folders it assigns the w320dp one to the tablet screens.
My toolbar for phone screens and xml is like this. It's assigning ones I don't want to phone screens. How can I override it and say for example this xml has to match with this specific phone screen size? Right now it's using XML and trying to fit it to a phone size that messes up everything.
Is there a way to assign a specific xml to a specific phone without it doing it for other phones?
I am designing an app with a .jpeg background and with text views on particular places on the screen. I designed this for my nexus 6 and used dp for the widths and heights of text views and margin-left and margin-top. What my understanding of dp is that it changes with every device according to screen size and density. So it should work on different phones according to the value of dp for them.
But this is not the case. When I run that app on a different phone (nexus 5) the layout is all messed up. I tried using the different resources and qualifiers for different screens (large, small, normal). But the problem still prevails. The app considers both nexus 6 and nexus 5 as large screens. How do i fix this?
this is not the best solution i guess.
i guess your layout is just on the layout folder. i don't know if the first device you tested the layout is large or small but what you should do is create another folder named layout-sw600dp. this folder is used by tablets. the folder layout is used my phones and smaller devices. you could also create the layout-land and layout-sw600dp-land folders for the landscape orientation.
dp do change depending on the device but if your layout gets messed up then i guess the layout called by that device doesn't fit its resolution. i guess dp becomes smaller if the device is bigger and vice versa.
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.
I want to provide 2 different layouts for these 4 devices. I want Nexus4 (1280x720) and Nexus7(1024x600) use layoutA and NexusOne/NexusS (both 800x480) to use LayoutB.
I read the developer guide and still cannot figure out what kind of qualification I should specify to the different layout folders in "/res".
What's more, I even want the NexusOne/NexusS to use layoutA in portrait mode and layoutB in landscape mode.
In a summary, the threshold of the difference is the width and the density of the screen. I want to:
w>480dp use layoutA
w<480dp use layoutB
Can I achieve these goals at the same time?
Take a look at the docs - http://developer.android.com/guide/topics/resources/providing-resources.html
For N4/N7 have the resource directories
layout-sw600/layoutA
For N1/NS have the resource directories
layout/layoutB
Taking into consideration landscape and horizontal layouts, have an additional directory for N1/NS alone.
N1/NS
layout-port/layoutA
It's wall written in the tutorial. The folders you want are:
/res/layout-sw480 with layout A
/res/layout-land-sw480 with layout B
/res/layout-land-sw720 with tablet and nexus4 layout
Thanks for the gentlemen's answers above. I have tried many combinations of the qualifications and finally figured out the correct one:
/layout - small layout for short width as N1/NS-port, QVGA-port
/layout-w360dp - big layout for large screens N4/N7, and for landscape mode of N1/NS and QVGA
/layout-land - same as above
This works fine for me. The trick here is that QVGA is ldpi, N7 is mdpi, N1/NS is hdpi, N4/GN is xhdpi. I haven't tried it on a screen smaller than 320x480
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