i want to change layout without calling the onCreate method. i also define android:configChanges="orientation|keyboardHidden" in my activity and it is not calling the onCreate method but the layout not adjust appropriately on landscape mode.
my current layout look like as follows.
after change orientation as landscape it look like as follows:
but on landscape i want the following result.
is there any auto adjacent property?
how can i do it?
Notice that Android does not call onCreate and onDestroy because we retained the Fragment; nor does it call the constructor, because the same Fragment instance will be used after the orientation change.
OnCreate is only called once.
Another most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change.
Conclusion: On rotation of screen, The Activity is Destroyed. The Activity is Recreated fresh in requested orientation.
there is no auto adjust property while view changes from portrait to landscape.
For images that you want to display in landscape mode
Create one filename.xml file and design your layout for landscape mode. Give filename same as your previous xml file in layout folder that you are using for activity.
Create folder in res/ name as layout-land and then keep that filename.xml file in res/layout-land folder
It will automatically call that res/layout-land/filename.xml when orientation changes from portrait to landscape.
Or you can also use
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
//your code
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//your code
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With