はじめに
今回はAndroidアプリ内で画面を縦画面、横画面でそれぞれ固定する方法を記事にします。
基本的に、指定がない場合は 端末を縦にすれば縦画面に、横にすれば横画面になるのがデフォルトです。
ですが、レイアウトやデザインによっては画面の回転に対応できないケースもあります。
そういった場合には、それぞれ指定してあげる必要があります。
指定方法
AndroidManifest.xml の manifest → application → activity に
”screenOrientation”
を追加します。
横画面に固定するには
<activity android:screenOrientation="landscape">
縦画面に固定するには
<activity android:screenOrientation="portrait">
また、縦横以外にも指定方法があるので表でまとめておきます。
screenOrientationの値 | 説明 |
---|---|
unspicified | デフォルトの状態、自動回転する |
landscape | 横向き固定 |
portrait | 縦向き固定 |
user | 現在のレイアウトに従う、ユーザーの操作により切り替え可能 |
behind | 親のactivityに従う、ユーザーの操作により切り替え可能 |
sensor | センサーの通りにする |
nosensor | センサーを無視する |