when we have two XML layout files for an activity one for portrait and one for landscape mode, is it necessary for their root views to have the same ID or they may have different?
-
possible duplicate of [How do I specify different layouts for portrait and landscape orientations?](http://stackoverflow.com/questions/2124046/how-do-i-specify-different-layouts-for-portrait-and-landscape-orientations) – barq Feb 13 '15 at 09:58
-
This is totally wrong I do not speak about neither layout Ids nor about how to create landscape resource. If you read the question I'm talking about if we can have totally different root view Ids for resources in portrait or landscape mode. So you downvoted the question before understanding it... nice attitude! Have a nice day. – gfot Feb 13 '15 at 10:03
2 Answers
IF you have separate layout files (i.e.: for different orientations), they can be completely different. however it depends how you would like to use them in your code.
Update:
To check orientation in code use:
getResources().getConfiguration().orientation
It is either ORIENTATION_LANDSCAPE
or ORIENTATION_PORTRAIT
.
http://developer.android.com/reference/android/content/res/Configuration.html#orientation

- 955
- 10
- 19
-
Actually I want to have different layout root view Ids in order to check when I'm in landscape mode. – gfot Feb 13 '15 at 09:59
-
Updated answer. (just use one layout for both if possible, that increases maintainability.) – Xyaren Feb 13 '15 at 10:03
If you do not need to use the view through a findViewById, then it won't be a problem to have different names. Generally, the layout changes depending on the orientation, but it contains the same views so you should ask yourself: Why do I want different name for my root view? If it's only to check the orientation, then you should not use this solution. See the answer on how to check orientation: Check orientation on Android phone