2012-07-03 42 views
0

I`ve鎖定我的顯示方向與處理變化的Android

this.setRequestedOrientation(
      ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

在我onCreate()方法和多數民衆贊成,當然,做工精細。現在我想處理我的顯示方向的變化。我想以與在Android相機中實現的相同的方式旋轉我的ImageView。有任何想法嗎? 非常感謝

+1

請使用se在發佈[SO] – Merlin

回答

0

在你的清單,你可以將此屬性添加到活動中要檢查:

<activity android:name=".MyActivity" 
     android:configChanges="orientation" 
     android:label="@string/app_name" /> 

而且你的活動代碼只是重寫此方法:

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

    // Checks the orientation of the screen 
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); 
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ 
     Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); 
    } 
} 

供參考:

http://developer.android.com/guide/topics/resources/runtime-changes.html

+0

上的重複問題之前,我感謝了很多,但是當我開始我的應用程序時它只顯示一次「橫向」,並且在我旋轉它時不會改變。 – Max