How to lock a layout in ORIENTATION_LANDSCAPE and another in ORIENTATION_PORTRAIT

3

I am using the method for when changing position layout change however when application start in landscape it starts the layout test_01 landscape mode being that its format is portrait how to fix this.

if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    setContentView(R.layout.activity_teste_02);
    inicializarInterface();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){    
    setContentView(R.layout.activity_teste_01);
    inicializarInterface();
}
    
asked by anonymous 13.03.2015 / 01:34

1 answer

3

You can use the res folder to create specific layouts for portrait or landscape.

The layout folder within the res folder, is for generic layouts, with no "treatment", for any type of screen (resolution or orientation).

If you want to create a specific layout for portrait, simply create a layout-port folder within your res folder. And, to create a landscape-specific layout, create a layout-land folder within your res folder.

Note : Do not forget to keep the same name for both layouts in both folders.

In your Activity you do not have to worry about what layout will be inflated, calling only setContentView(R.layout.seu_layout) and letting Android take care of the rest

For more details, please follow the official documentation: link

    
13.03.2015 / 01:44