[Kotlin, Java] Activity 화면 방향 설정


안드로이드의 Activity 설정 시 Orientation을 지정하는 방법을 설명합니다.

 

AndroidManifest.xml에 Orientation 설정을 바꿀 Activity에 대해 특성 한가지만 추가(수정)해주면 됩니다.

 - android:screenOrientation = "옵션값"

  -> screenOrientation 특성은 Activity의 방향을 설정할 수 있습니다.

  -> 단, Activity가 다중창모드(멀티태스킹, 화면 분할)로 실행이 된다면 이 특성은 무시됩니다.

  -> 옵션값 (자주 사용할만한 옵션값에는 Bold 처리)

 

unspecified behind landscape portrait
reverseLandscape reversePortrait sensorLandscape sensorPortrait
userLandscape userPortrait sensor fullSensor
nosensor user fullUser locked

 

-> 자주 사용하는 옵션값만 설명을 하자면,

 landscape는 Activity를 가로방향으로 고정합니다.

 portrait는 Activity를 세로방향으로 고정합니다.

 sensorLandscape는 Activity를 가로방향으로 고정을 하고, sensor의 값에 따라 반전이 될 수 있습니다.

 sensorPortrait는 Activity를 세로방향으로 고정을 하고, sensor의 값에 따라 반전이 될 수 있습니다.

 sensor의 경우 사용자가 들고있는 방향에 따라 Activity의 방향이 결정됩니다.

  -- sensor 사용시 4방향에 대한 설정이 이루어지지 않는다면 fullSensor를 사용해 보세요.

 

 - AndroidManifest.xml에서 설정하는법.

방향 설정을 원하는 Activity 설정 안에 android:screenOrientation 특성을 주어 원하는 옵션값을 부여합니다.

(원하는 옵션값은 상단에서 선택합니다.)

* Android Studio 3.6 이상에서는 사용자가 screenOrientation을 지정하면 에러를 낼 수 있습니다.

 - 이는 unspecified(default -> 시스템이 방향을 선택)와 fullSensor 이외의 옵션값을 사용할 때 일어나는 문제로, tools:ignore="LockedOrientationActivity" 특성과 옵션값을 주어 에러를 무시할 수 있습니다.(오류 무시)

 

<activity
  android:name=".MainActivity"
  android:screenOrientation="portrait"
  tools:ignore="LockedOrientationActivity">
</activity>

 

참조

https://developer.android.com/guide/topics/manifest/activity-element?hl=ko

 

<액티비티>  |  Android 개발자  |  Android Developers

Declares an activity (an Activity subclass) that implements part of the application's visual user interface. All activities must be represented by {@code } elements in the manifest file. Any that are not declared there will not be seen by the system…

developer.android.com

 

버전정보 (v1.0)

 - v1.0 2020.06.26 배포

 

* 저작권에 위반될 수 있는 컨텐츠(이미지, 동영상 등)나 게시글은 삭제되거나 수정될 수 있습니다.

* 문제의 여지가 될 수 있는 컨텐츠의 경우 댓글 달아 주시면 빠른 시일 내에 조치하도록 하겠습니다.

* Karzin은 항상 공부중입니다. 설명이 틀리거나 잘못된 부분이 있다면 의견내주시는대로 수정하도록 하겠습니다.

 

Karzin

abbeea@naver.com




+ Recent posts