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?

4

5 回答 5

22

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

于 2014-03-18T10:24:11.487 回答
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.

于 2014-03-26T08:36:41.203 回答
1

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.

于 2020-10-02T06:24:14.190 回答
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

于 2014-09-30T09:45:47.600 回答
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.

于 2017-11-29T06:05:40.500 回答