I have searched for an exactly similar topic/problem but didn't find. My problem is that 720*1280 layout(Galaxy Nexus) and 480*800 layout(Nexus S) are using the same layout. I have created layout
, layout-large
, layout-small
, layout-xlarge
folders/layouts and I'm supporting now a much more devices resolution, however, I have a scaling problem with 720*1280 and also 480*854 , 480*800 resolutions. My question is can I make a specific layout for a specific resolution? I'm always using margin left/right and it can work for a specific resolution and not in other.
Thank you.

- 3,117
- 11
- 50
- 107
3 Answers
See table in this section. So you can specify screen size, you can use: sw<N>dp
or w<N>dp
or/and h<N>dp
.

- 32,568
- 6
- 55
- 140
-
i created a `layout-h720dp` and when i select Galaxy Nexus from normal-layout the layout in that folder is triggered but i have that error: `'Extra Large Screen' is not a best match for any device/locale combination Displaying it with '...` – androniennn Dec 01 '12 at 14:59
-
dp is a spatial unit reflecting physical dimension, so you have to recalculate from pixels to dp. http://developer.android.com/guide/practices/screens_support.html#dips-pels SGN has higher density of pixels. – Marek R Dec 01 '12 at 15:23
Instead of using screen size classes you can try using more literal selectors, i.e.:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw480dp/main_activity.xml # For screen width 480 dp like Nexus S
res/layout-sw720dp/main_activity.xml # 720dp wide and bigger
See this developer's article: Declaring Tablet Layouts

- 72,056
- 11
- 123
- 141
-
I created layout-sw720dp folder and created an xml file, when i click on it i have 10.1 WXGA (Tablet) launched, not Galaxy Nexus. I'm not doing it incorrectly? – androniennn Dec 01 '12 at 15:01
-
Not just when selecting Galaxy nexus, but even with others. When i'm on normal layout and select Nexus one the file is triggered – androniennn Dec 01 '12 at 15:06
see below links
Samsung Galaxy Nexus layout/drawable structure?
Which android layout and drawable resources should galaxy tab support for development?
If you want your App to support maximum devices, try to make a general layout which fits for all device, there may be minor trade offs, but one can live with that. You can make such a layout by using Relative Layout as much as possible, if there come a situation where you can not handle multiple device support, try handling it with code at run time, but in such a manner, that it runs on all device (For-Example think of percentages instead to fixed height or widths etc)
-
So i forget about `LinearLayout` and static marging left/right/top/bottom? I replace it with percentages(do u have an example?)?I create drawables in all dpi (large,xlarge...) ? – androniennn Dec 01 '12 at 17:04
-
1You will need LinearLayout but less often, margins and text sizes are two thing which you have to give static but with very CARE and test layouts on all devices you have (or emulator), this is the trade off which i said earlier. I you are following what I said then you just have to make 1 layout per activity and place it in layout folder. – Androider Dec 01 '12 at 17:29
-
1I don't have any example, before this I was also working like you, means having different layouts for each device, but now I learned this. This technique needs experience. – Androider Dec 01 '12 at 17:31
-
And what about tablets layouts? You just put xhdpi drawables in right folder and make some corrections ? – androniennn Dec 01 '12 at 17:45
-
Dynamic layouts will handle mobile and tablets automatically. As far as drawables are concerned you can have only 1 image, scale up and down at run time according to device width/height and picture's width/height. Get pic to device ratio and then scale up and down. Here you will use percentages – Androider Dec 01 '12 at 17:51
-
Aaa I'm really finding problems with tablets! What do you do in your projects with tablets layouts? – androniennn Dec 01 '12 at 17:52
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/20450/discussion-between-syed-zahid-ali-and-androniennn) – Androider Dec 01 '12 at 18:05