1

I want to make a separate landscape layout for each size of my original layout

I have activity_main.xml. I have adapted it to be able to fit multiple screen sizes:

enter image description here

Now, I want to create a landscape layout for each different screen size. The android docs and many (Many!) stack overflow pages suggest to do something like this to create a new landscape layout:

enter image description here

But after doing this, I create a landscape layout for all of the activity_main.xml's I need a separate landscape for the large activity_main, the small activity_main, the xlarge activity_main, and the normal activity_main. By doing the method described everywhere, I end up with this:

enter image description here

And because this covers all of the activity_main.xml's, I don't get the option to 'Create Landscape Variationon my other versions of myactivity_main`.

So, how do I get separate landscape layouts for each already made variation of activity_main?

Thanks so much,

Ruchir

Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
  • have you try to visualize this in project structure . I can see in image that you are in android structure right now . you can find drop down menu above your project and select project from there. – KDeogharkar Dec 03 '15 at 04:52
  • Yes, I have. Here is a screen shot of it in project structure: http://i.snag.gy/L7VNO.jpg – Ruchir Baronia Dec 03 '15 at 04:56
  • yes now it has different folder right . so now here you can define your new folder or rename your current layout folder that suits your need. – KDeogharkar Dec 03 '15 at 04:58
  • @KDeogharkar What should the name of the new folder be to add? – Ruchir Baronia Dec 03 '15 at 04:59
  • according to the the docs you only have 2 choices. small screens and large screens. layout-land, layout-large-land -- http://developer.android.com/training/basics/supporting-devices/screens.html – Tasos Dec 03 '15 at 05:00
  • @Tasos Is there any way to do this in android studio without having to create it manually? For example like the button which just makes another of the same layouts for a different screen? – Ruchir Baronia Dec 03 '15 at 05:06

5 Answers5

3

Follow this steps given in Image enter image description here

select Project instead of Android where i highlighted in Image, and expand your file from Projectname-> app->src->res-> and see seprate all folders

now -> right click on res-> new-> directory-> layout-land-hdpi

create like this

layout-land-hdpi

layout-land-ldpi

layout-land-mdpi

layout-small-land-ldpi

Rajesh
  • 2,618
  • 19
  • 25
  • Thanks so much Survivor! I have liked. Thanks for the detail, I am sure it will be very helpful to others who come across the question. Great screen shot! – Ruchir Baronia Dec 03 '15 at 05:23
  • Except I have one more question...Can I remove the `layout` if I already have `layout-normal`? – Ruchir Baronia Dec 03 '15 at 05:34
  • the layout and layout-normal are similar it is batter if you remove layout-normal instead of layout it's my suggestion – Rajesh Dec 03 '15 at 05:36
1

Right-click on res then select "New" -> "Android Resource Directory". Give it the name "layout-large" and the type "layout". Copy "activity_main" of "layout" (in step 3) to the clipboard and paste it in "layout-large". do the same for different screen sizes.

Android Resource Directory names are like:

layout,
layout-land,
layout-large,
layout-large-land,
layout-sw600dp,
layout-sw600dp-land,
layout-sw720dp,
layout-sw720dp-land 

and so on

Manoj kumar
  • 450
  • 4
  • 13
  • How will that make it landscape...? – Ruchir Baronia Dec 03 '15 at 04:52
  • -land defines the landscape orientation for the android application which is recognized by the gradle as well as the android os. give it a try so that you may find an answer – Manoj kumar Dec 03 '15 at 04:56
  • Put a modified layout for landscape in there and it will be shown, when the phone is on landscape. – dabo248 Dec 03 '15 at 04:56
  • I already have it in landscape, as my screenshot suggests: http://i.stack.imgur.com/iqrZu.png **I want to make a separate landscape layout for each size of my original layout** – Ruchir Baronia Dec 03 '15 at 04:58
  • ya i saw the screen shot create a separate Android Resource Directory for each resolution and add your lanscape xml inside it and your problem is solved – Manoj kumar Dec 03 '15 at 05:00
  • Except I have one more question...Can I remove the `layout` if I already have `layout-normal`? PS: I have liked :) – Ruchir Baronia Dec 03 '15 at 05:34
  • Yes, you can. the normal layout folder is a default call only when there is no more layouts in ur other layout folder – Manoj kumar Dec 03 '15 at 06:51
1

So, your current structure is:

layout
layout-large
layout-normal
layout-small
layout-large

To specifiy layouts for landscape mode for each of these sizes create the following folders and put your size-specific layouts in there:

layout-land
layout-large-land
layout-normal-land
layout-small-land
layout-large-land
dabo248
  • 3,367
  • 4
  • 27
  • 37
  • Thanks for the answer dabo. Is there any way to do this in android studio without having to create it manually? For example like the button which just makes another of the same layouts for a different screen? – Ruchir Baronia Dec 03 '15 at 05:07
  • Not that I knew. I would also recommend to create them manually, because then you know exactly what you did and don't need to assume what the button did for you. Just copy all your normal layout folders, add "-land" and adjust them for landscape, that's it. – dabo248 Dec 03 '15 at 05:09
  • Should I make it in the package view? – Ruchir Baronia Dec 03 '15 at 05:11
  • I recommend to use the project view, it shows you all directories and files. – dabo248 Dec 03 '15 at 05:12
  • Thanks so much dude. I have marked you best answer and liked your post. Thanks! – Ruchir Baronia Dec 03 '15 at 05:22
  • Except I have one more question...Can I remove the `layout` if I already have `layout-normal`? – Ruchir Baronia Dec 03 '15 at 05:32
  • Yes, you can. The default layout folder is just a fallback when there are no more specific layouts in your project. Just take care to define a layout for all above mentioned sizes, or, during runtime, the system will pick any of them with the nearest specification, which might not look as desired. – dabo248 Dec 03 '15 at 05:38
1

you will find all information about layout support . Look into Using configuration qualifiers

enter image description here

KDeogharkar
  • 10,939
  • 7
  • 51
  • 95
  • Thanks so much! I have liked. Thanks for the detail, I am sure it will be very helpful to others who come across the question. – Ruchir Baronia Dec 03 '15 at 05:24
  • yes it has all detail not only about layout but also about drawable folder so it is very helpful while designing android layout with compatibilities. – KDeogharkar Dec 03 '15 at 05:27
  • Except I have one more question...Can I remove the `layout` if I already have `layout-normal`? – Ruchir Baronia Dec 03 '15 at 05:34
1

Android powers hundreds of device types with several different screen sizes, ranging from small phones to large TV sets. Therefore, it’s important that you design your application to be compatible with all screen sizes so it’s available to as many users as possible.

But being compatible with different device types is not enough. Each screen size offers different possibilities and challenges for user interaction, so in order to truly satisfy and impress your users, your application must go beyond merely supporting multiple screens: it must optimize the user experience for each screen configuration.

Please read SO Answers

  1. Android layout folders

  2. Creating landscape layouts

  3. Android Landscape Layout
Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198