Android 画面向き

Android 画面向きを設定など。。。

(1) AndroidManifest.xml で設定

    android:screenOrientation を指定

<activity android:name=".test.SampleActivity"
           android:screenOrientation="portrait">

android:screenOrientation="portrait"   →縦向きに固定
android:screenOrientation="landscape" →横向きに固定
android:screenOrientation="nosensor" なら、起動時の向きのまま。

それよりも、、画面向き変更で再描画させない設定をよく使う。
android:configChanges="keyboardHidden|orientation"



(2) Activity の中で動的にセット

 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);