0

我正在开发一个应用程序,它有一个活动有两种不同的视图LandscapePortrait模式。处理方向一切都很好,但问题是我想先显示Landscape模式,然后用户可以稍后将方向更改为纵向,无论之前的活动是否处于Portrait模式。

当我landscape在清单中强制定义方向或通过调用onCreate setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 然后方法onConfigurationChanged

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);
    }

没有被调用。

我也定义了

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"

在清单中。

任何帮助都将是可观的。

4

1 回答 1

0

在您的活动代码中使用 OrientationEventListener 尝试此替代选项:

private OrientationEventListener orientationEventListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int orientation) {

            // ....

        }
    };

    if (orientationEventListener.canDetectOrientation()) {
        orientationEventListener.enable();
    }

}

@Override
protected void onDestroy() {
    super.onDestroy();
    orientationEventListener.disable();
}
于 2014-09-02T10:50:29.183 回答