-1

我正在開發一個應用程序有一個活動有LandscapePortrait模式的兩個不同的意見。處理方向的一切都很好,但問題是我想首先顯示Landscape模式,然後用戶可以更改方向爲以後是否以前的活動在Portrait模式。開始在橫向模式下的活動,它可以旋轉到縱向也

當我強行定義定向landscape在清單或通過調用的onCreatesetRequestedOrientation(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" 

任何幫助將明顯。

+0

「秀風景模式,然後再用戶以後可以改變方向爲縱向。」所以,用戶處於肖像模式,活動開始風景。如果他們想要肖像,他們需要旋轉設備兩次? – 2014-09-02 10:44:10

+0

什麼是非手動設置方向到風景鎖定方向改變,所以onConfigurationChanged方法沒有得到調用。嘗試使用 – 2014-09-02 12:22:00

回答

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(); 
} 
+0

,但這些值不適合定位。 – 2014-09-02 12:08:08

相關問題