1
1

More than 1 year has passed since last update.

【Android】画面を縦方向、横方向で固定する

Posted at

はじめに

今回はAndroidアプリ内で画面を縦画面、横画面でそれぞれ固定する方法を記事にします。
基本的に、指定がない場合は 端末を縦にすれば縦画面に、横にすれば横画面になるのがデフォルトです。
ですが、レイアウトやデザインによっては画面の回転に対応できないケースもあります。
そういった場合には、それぞれ指定してあげる必要があります。

指定方法

AndroidManifest.xml の manifest → application → activity に
”screenOrientation”
を追加します。

横画面に固定するには

<activity android:screenOrientation="landscape">

縦画面に固定するには

<activity android:screenOrientation="portrait">

また、縦横以外にも指定方法があるので表でまとめておきます。

screenOrientationの値 説明
unspicified デフォルトの状態、自動回転する
landscape 横向き固定
portrait 縦向き固定
user 現在のレイアウトに従う、ユーザーの操作により切り替え可能
behind 親のactivityに従う、ユーザーの操作により切り替え可能
sensor センサーの通りにする
nosensor センサーを無視する
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1