user434885
user434885

Reputation: 2018

Android dev: screen orientation

is it possible to change the layout of the app when the orientation of the screen changes from portrait to landscape ? I mean linking the app to two different .xml layout files for each landscape and portrait? or maybe is it possible to change placement of 2 views ? like... i want a button to be below the textview in portrait mode but i want them side by side in landscape mode... :/ please help...

Upvotes: 1

Views: 711

Answers (2)

smith324
smith324

Reputation: 13060

Yes its actually very easy. In your res folder you have a layout folder with you layouts. Make a layout-land folder for your landscape layouts. The .xml files should have the same name as their counter parts in the layout folder. Android will automatically pick the right one at runtime during onCreate in your activities.

/res/layout - default if none exist for a particular condition /res/layout-land - landscape layouts.

Note, you do not need to create duplicates if nothing is different for a particular layout, it will just use the default.

Upvotes: 1

Kevin Coppock
Kevin Coppock

Reputation: 134664

Yep, it's one of the basic layout tips, might want to read through the tutorials on developer.android.com.

For this instance, just put the separate layout in res/layout-land (you'll have to make a new folder) with the same name as the portrait layout.

Upvotes: 1

Related Questions