10

I've been looking at issues in stackoverflow and I've tried everything I've seen but the layout-land not work. In my code I have and the method onConfigurationChanged

@Override
 public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);           
}

And the manifest file:

<activity
        android:name="com.sde.PlayerTrack"
        android:theme="@style/AppTheme"
        android:configChanges="orientation|keyboardHidden|screenSize"
        >
    </activity>

I tried also to remove in the android manifest entry: configChanges and then the layout land load but the components i have (TextView, scrollbar ...) does not work properly.

Can you help me, please?

Jitesh Upadhyay
  • 5,244
  • 2
  • 25
  • 43
Garmael
  • 422
  • 3
  • 7
  • 19

5 Answers5

25

Remove orientation from the android:configChanges in your manifest file, and put you landscape layout xml file into layout-land folder.

Saurabh Bhandari
  • 2,438
  • 4
  • 26
  • 33
Cheerag
  • 415
  • 3
  • 10
  • 1
    I already did that before and it works but I have progressbar not working properly. Thanks. – Garmael Mar 18 '14 at 11:14
  • what exactly problem you are facing with progressbar, Can you explain in detail? – Cheerag Mar 19 '14 at 08:29
  • I have an asynchronous class that loads a song just start the activity. Then when the screen rotates the land layout works but the song is not continuous but is reloaded. – Garmael Mar 19 '14 at 08:54
  • This way will do reload data. Not good. I want when rotate screen, no reload data, which only auto select layout in layout-land or layout-port folder. Please help me. – MrSiro May 14 '16 at 09:03
  • Mistakenly left configChanges in manifest. Can't thank you enough for this answer. Was just about to give up. – Umair Mar 03 '23 at 16:22
10

Finally, my solution is:

AndroidManifest.xml File:

<activity
        android:name="activity.name"
        android:configChanges="orientation|keyboardHidden|screenSize"       
        >

And in the activity implement the method onConfigurationChanged (Configuration newconfig):

@Override
 public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);     
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            createHorizontalalLayout();            
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
            createVerticalLayout();             
        }
}

With createVerticalLayout () and createHorizontalLayout () programmatically do the layouts.

Ramki Anba
  • 754
  • 1
  • 10
  • 21
Garmael
  • 422
  • 3
  • 7
  • 19
2

For me the missing piece was clean build. Somehow my changes were not reflecting. Here are the steps that I performed.

  1. creating a layout-land folder parallel to the layout folder.

  2. copying activity_main.xml to layout-land folder and modifying activity_main.xml for a landscape layout.

  3. It is important that you are able to preview both layouts in the design view. When you go to the design view of the layout file, you see a mobile rotate type of icon. You should be able to switch between layout previews using that icon. If you are able to switch that means your folder structure is correct. You can even do step 1 and step 2 using this. Make sure that you Fix layout errors.

  4. Your AndroidManifest.xml should not have "orientation" item in attribute android:configChanges=""

For me it is empty as of now

<activity android:name="com.sudoxer.app.MainActivity" android:configChanges="">
  1. Clean the project and rebuild it after this change.

You should see what you expect.

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
Sandeep Dixit
  • 799
  • 7
  • 12
0

Check emulator if you are running Android Emulator 4.4 it has some kind of bug in it's orientation. I had the same problem changed my emulator to 4.0.3 and everything worked fine. Visit here for more details site

wayzz
  • 585
  • 6
  • 23
0

I had this problem and after much debugging found the culprit in the build.gradle file. Android studio had added the line

sourceSets { main { res.srcDirs = ['src/main/res', 'src/main/res/layout-land'] } }

while I was messing around trying to create layout-land manually. I removed that line and normal function returned.