I would like to rotate Buttons/TextViews/etc. on screen orientation change but I want to keep layout unchanged. How can it be done? I'm using LinearLayouts.
This is what I mean:
I would like to rotate Buttons/TextViews/etc. on screen orientation change but I want to keep layout unchanged. How can it be done? I'm using LinearLayouts.
This is what I mean:
Create
res->layout->layout-land
and put your xml file for landscape mode
Your layout file in layout
folder is only for portrait mode Now if you need landscape then create layout-land
folder.
It can be done it two ways:
1.) Either you define a new xml file in layout-land
folder.
2.) Use android:configChanges="orientation"
in your activity tag inside manifest.xml
Then in your activity class:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
ChangeToLandscape();
} else {
ChangeToPortrait();
}
}
LayoutParams lp;
public void ChangeToLandscape() {
lp = new LayoutParams(new ViewGroup.MarginLayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
textView1.setLayoutParams(lp);
lp.setMargins(0, 0, 0, 0); // Whatever you want
// Similar for other views
}
//Similarly, implement `ChangeToPortrait()`
Hope it helps !!!
You'll have to change the layout parameters.