2

我已经为纵向和横向的大屏幕创建了布局,并且在两种布局中都有一个 signin.xml,但是当我更改屏幕方向时,它不会加载横向 xml,而是更改为横向模式,但纵向 xml 是已加载。我也提到了清单中的 onconfig 更改,请让我知道如何在方向更改时保存数据,并请给我一些示例。

下面是我的java代码

              public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);

               Display display = ((WindowManager)       getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
            int   orientation = display.getOrientation(); 
            boolean oAllow = false;
            switch(orientation) {
            case Configuration.ORIENTATION_PORTRAIT:
            if(!oAllow ) {
                    setRequestedOrientation    (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

            }
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            if(!oAllow) {
                    setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
            break;
    }
      }

当我将横向更改为纵向到横向时,如何获得横向视图?

请问有什么建议吗?提前致谢

4

2 回答 2

2

您的纵向 xml 文件夹布局还是布局纵向?如果它的布局纵向,请不要这样声明。只需创建默认的“布局”文件夹,当方向为纵向时,操作系统将获取 xml。

接下来,在 java 中注释上述代码,并在 androidmanifest.xml 中声明 android:configChanges="keyboardHidden|orientation" 在你的活动声明前面并测试它是否有效。

于 2012-05-22T07:09:16.087 回答
1

why exactly are you overriding onconfigchanges? This might be what messes up your layout. android is able to handle the layout changes when you have a layout and layout-land folder containing your layouts.

于 2012-05-22T06:44:49.143 回答