You have 2 possible solutions:
- Create different layouts for
portrait
andlandscape
modes (they will be places underlayout
andlayout-land
folders respectively). - Create a container in your layout (
FrameLayout
, for example). And add corresponding view to it in runtime depending on orientation.
Anyway, since both orientations use different elements, in your code you should add the following if
statement:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
} else {
}