8
votes

I am struggling for layouts for an Android app. I have defined different layouts for different screen sizes and the current layout directory structure is something like this:

  • layout
  • layout-land
  • layout-small
  • layout-xlarge
  • layout-xlarge-land

Problem

The main layout directory files are being displayed for 3.7 to 7.0 which is a very broad range. And text overlap on small screens and if I adjust on small; it becomes very tiny on the large screen.

According to me, the layout small files should be rendered for smaller screens but those files are only rendered for android wear devices.

layout-xlarge seems to work for Nexus 9 to Nexus 10

I want to know, how can I define the different layout for 3.7-5.0 and 5.0-7.0 screen sizes.

5
You should use Size Qualifiers instead of Configuration Qualifiers to have more controlmaRShmallow
As pointed out by @maRShmallow, the size qualifiers you've listed have been deprecated since Android API level 13. A more reliable classification system is the sw<N>dp configuration qualifiers which define the smallest width (sw) in dp of the screen in use. For example, I have run into size qualifiers classifying a Nexus 6 as a "tablet", but I was able to remedy this knowing that device is under sw600dp, the cutoff for standard 7" tablets. Source: developer.android.com/guide/practices/…M. Palsich
thank you, but same issue with sw<N>dp qualifier. The 320dp layout file is displayed for 3.7 to 6.0. Any solution?Alena
don't need to make multiple layout just remember don't fix size of layout.Farhana Naaz Ansari

5 Answers

22
votes

The answer is already given by user5594218 but looks like you are still unclear. (maybe you are beginner)

So, here is the step by step guideline

Solution 1: (short and simple)

  1. Navigate to app > src > main > res

  2. Duplicate layout directory by copying and pasting

  3. Rename duplicated Directories e.g layout-sw300dp

Solution 2: (bit lengthy)

  1. Create new resource directory: res > New > Android resource directory

Create new resource directory

  1. Select Resource Type as layout

  2. Add sw<N>dp in Directory name e.g layout-sw300dp and Hit OK

enter image description here

  1. Navigate to app > src > main > res

  2. Copy layouts XML file inside new directory

    //repeat process for other qualifiers
    

List of Qualifiers to support all screens:

  • layout-sw300dp
  • layout-sw330dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

Testing:

This is how it gonna look like, if you did it right. enter image description here

For more detail and examples, check: Android Application Development All-in-One For Dummies

3
votes

Create folders like the following

layout-sw300dp
layout-sw330dp
layout-sw480dp 
layout-sw600dp 
layout-sw720dp 

Create also values-folders like

values-sw300dp 
values-sw330dp 
values-sw480dp
values-sw600dp
values-sw720dp
1
votes

Navigate app-> res-> layout and right click then New-> layout resource file write the filename correctly and from available qualifiers choose the size you want.

0
votes

Dear you don't need to declare layout for various screen. just make single layout for every screen and don't fix the width and height of layout. you have to keep height either match parent and wrap content as well as for width.

-1
votes

you should try dp in your layout-height/layout-width/textsize as it is independent of screen sizes.