0

我想在縱向(即使該設備在橫向持有)安卓:啓動活動總是在肖像,但承認取向變化

總是開始一個新的活動/意圖如果我使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 活動被鎖定以肖像,但我想承認方向的變化。

所以我想我必須在第一次啓動時調用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);,當活動被創建時,需要一個監聽器來消除這個限制。

但是我應該在哪種方法中做到這一點?在構造函數中,或在onCreate()或其他地方???

+1

http://stackoverflow.com/questions/6293563/android-listen-for-orientation-change – Triode 2013-04-10 12:22:52

回答

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

     System.out.println("on config change method called."); 

     if(Configuration.ORIENTATION_LANDSCAPE==newConfig.orientation) 
     { 

        //Portatrate to landscape... 
      System.out.println("on config change method called portraite mode."); 
     } 
     else if(Configuration.ORIENTATION_PORTRAIT==newConfig.orientation) 
     { 
      //Landscape to portraite.... 
      System.out.println("on config change method called landscape mode."); 
     } 
     }