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 fi开发者_StackOverflow中文版les 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...
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.
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.
精彩评论