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

user3173888
  • 95
  • 1
  • 4
  • Check this http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android and http://stackoverflow.com/questions/3097909/android-orientation-change-calls-oncreate – Subhalaxmi Jan 23 '14 at 14:35

1 Answers1

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

Jitesh Upadhyay
  • 5,244
  • 2
  • 25
  • 43
  • 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?? – user3173888 Jan 24 '14 at 13:31