2

Can we create different layout XML file for different ldpi sceens.

now a single file is placed in the layout-ldpi folder. i want to create two layout XML file for following emulator size

3.3 WQVGA (240x400 ldpi)

3.4 WQVGA (240x432 ldpi)

Can we make folder something like layout-ldpi 3.3

layout-ldpi 3.4

and put the different XML in two folders is it possible ?

Please help me

Amith
  • 1,907
  • 5
  • 29
  • 48
  • 1
    i think both will take the ldpi folder layout files only. if u want to force to select different layout means you can do it runtime by giving different layout for respective screens. – Tamilselvan Kalimuthu Dec 03 '13 at 09:24

3 Answers3

5

These tutorials will help you

1 - Text Tutorial Android Supporting multiple screens

2 - Video Tutorial Multiple Screens

For Small explanation!

Yes you can do it.

Supporting Multiple Screens

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png  

@Henry Thompson

and then u need to create a main.xml for each one with the same name.

By placing the layout XML files in different folders you can get Android to load the correct one depending on the screen density. For example, if you layout is called "main.xml":

  • Placing the file in /res/layout-ldpi/main.xml will mean it is used only in low density (or above)
  • Placing the file in /res/layout-mdpi/main.xml will mean it is used only in medium density (or above)
  • Placing the file in /res/layout-hdpi/main.xml will mean it is used only in high density (or above)

  • Placing the file in /res/layout-xhdpi/main.xml will mean it is used only in extra-high density

Supporting Different Screen Sizes

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

For WVGA Screen , i can load layout and it can be changed according to screen

if (width == 480 && height == 800)
    {
        setContentView(R.layout.main); // load different layout as per screen size or specifications
    }

3rd Update - Answer to How to find its ldpi , mdpi etc

Already answered here @solution ldpi mdpi

Community
  • 1
  • 1
Digital Alchemist
  • 2,324
  • 1
  • 15
  • 17
-1

Yes, definitely you can... You can change the layout in different folders as per requirement...

Looking Forward
  • 3,579
  • 8
  • 45
  • 65
-1

you can simply get the dimensions of the screen of any device and adjust them.