0

I want to have different layout files for portrait and landscape orientation, so i created new folder layout-land, placed the landscape layout to this, portrait layout to normal layout folder. layouts are changing properly as per the orientation change but it is calling oncreate method of activity everytime i change the screen orientation.My question is

Without reloading the activity, need to manipulate only layout so that all the views modified in portrait should retain in landscape with changes as per the layout only file.

Please help me to achieve this.

Thanks

1

1 Answer 1

0

hi please do this in this way

 @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
      }
    }

the another solution can be in is here that use folloing in AndroidManifest.xml add this to activity:

android:configChanges="orientation|keyboardHidden"

however not a best practice to use it!!

please visit also

http://xjaphx.wordpress.com/2011/09/19/the-less-known-over-screen-orientation/

visit http://developer.android.com/reference/android/app/Activity.html#onConfigurationChanged%28android.content.res.Configuration%29

http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

1
  • thanks for reply. when i tried all those but layout is changing thats good but in portrait i have some changed the visibility of the view, then change to landscape then it is rendering the default layout file but view i changed in portrait did not reflected. how i can achieve this?? Jan 24, 2014 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.