Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change orientation without onCreate call

Tags:

android

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.

alt text

after change orientation as landscape it look like as follows: alt text

but on landscape i want the following result.

alt text

is there any auto adjacent property?

how can i do it?

like image 494
Kamran Omar Avatar asked Oct 29 '10 06:10

Kamran Omar


People also ask

Is onCreate called when orientation changes?

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.

Is onCreate only called once?

OnCreate is only called once.

How do you change orientation when retaining data?

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.

What will happen to the activity life cycle if we change the device orientation?

Conclusion: On rotation of screen, The Activity is Destroyed. The Activity is Recreated fresh in requested orientation.


1 Answers

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
      }
    }
like image 97
krunal shah Avatar answered Sep 20 '22 06:09

krunal shah