Why don't you try to recognize the screen orientation. whenever screen changes it recreates the activity you can get screen orientation via fallowing method
int orientation=this.getResources().getConfiguration().orientation;
if(orientation==Configuration.ORIENTATION_PORTRAIT){
//code for portrait mode
}
else{
//code for landscape mode
}
try to add your layout programmatically. If you are using Relative layout you can use addRule like this
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, height);
lp.addRule(RelativeLayout.BELOW, lastId);
You can add rules as per requirement. above is the way to add a rule. similarly there is a method to remove a rule
params.removeRule(RelativeLayout.BELOW);
Or if you want, can inflate a new layout in condition as per your need.
Hope this will help!