How To Start A New Activity When Screen Orientation Changes? Android
I am writing an application which in portrait view has a gallery at the top and when you click a picture it will inflate and fill the entire screen. This works however in landscape
Solution 1:
The right way to do it is to define two layouts, one in layout-port and one in layou-land directories. That is, you will have the following two layouts:
res/layout-port/main.xml
and res/layout-land/main.xml
.
In your software you simply write secContentView(R.layout.main);
and android will take care of applying the right layout upon device rotation.
Solution 2:
Solution 3:
Add this to your Activity:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
startActivity(newActivity)
}
Note that this is a bad idea. Actually, it's a really bad idea. A much better alternative would be to either force one orientation or to create a layout that looks great on both orientations.
Post a Comment for "How To Start A New Activity When Screen Orientation Changes? Android"