액티비티의 스크린 오린엔테이션 설정을 보통 AndroidManifest.xml 파일에서 설정을 한다.
<activity
android:name=".Main"
android:screenOrientation="landscape"
/>
하지만, 하나의 액티비티로 여러 가지 뷰(가로형/세로형)를 표현할 경우 동적으로 전환을 해주어야 한다.
Activity에 setRequestedOriention() 메소드가 존재한다.
void android.app.Activity.setRequestedOrientation(int requestedOrientation)
public void setRequestedOrientation (int requestedOrientation)
Since: API Level 1 Change the desired orientation of this activity. If the activity is currently in the foreground or otherwise impacting the screen orientation, the screen will immediately be changed (possibly causing the activity to be restarted). Otherwise, this will be used the next time the activity is visible.
ParametersrequestedOrientation An orientation constant as used in ActivityInfo.screenOrientation.
다음과 같이 코드에서 직접 설정을 할 수 있다.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);