2010년 12월 30일 목요일
[Android Course][English][Theme] - screenOrientation / Rotation
Android 'Rotation / screenOrientation' Let's examine each of the relevant information.
1. screenOrientation
(1) 'Xml' Setting
: "AndroidManifest.xml" in the Activity Tag "android: screenOrientation" When you are setting.
- Portrait: 'vertical' Show only
- Landscape: 'horizontal' Show only
- Norsensor: 'horizontal and vertical' transitions both X
- Sensor: 'Aspect' convert all O
=> Cons: phone 'Settings - System - Display - Automatic screen rotation feature and independent works.
In other words, the 'Auto Screen Painting' and 'Diable' rotation is set to'm in is the problem.
- Unspecified: 'Aspect' convert all O
=> Features: Pawn 'Settings - System - Display - Automatic screen rotation feature based on the works.
In other words, the 'Auto Screen Painting' and 'Diable' If you set the rotation does not work.
(2) 'Code' Setting
: Code on the "setRequestedOrientation ()" API to be used.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
...ETC...
2. 'Rotation' NOTICE
: Android will support the screen rotation feature.
However, if there is any set, each time rotating existing Activity does not preserve the Data. In other words, the horizontal / vertical conversion while at the UI Activity of a newly drawn onDestroy () and onCreate () is being performed.
1) 'onDestroy() & onCreate()' How not to reload
- 'AndroidManifest.xml' Setting
: android:configChanges="keyboardHidden|orientation"
- 'Code' Setting
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
switch(newConfig.orientation) {
case Configuration.ORIENTATION_PORTRAIT:
.....working......
break;
case Configuration.ORIENTATION_LANDSCAPE:
.....working......
break;
}
}
: Activity is being reloaded because the screen size remains unchanged. Therefore, 'Code' section of the above would have to work.
2) 'onDestroy() & onCreate()' 호출 시, Data Backup 방법
- Screen rotation, Data Save.
: 'Public Object onRetainNonConfigurationInstance ()' on the screen, in turn, is to store the data coding.
public Object onRetainNonConfigurationInstance() {
HashMap<String, Object> DataBackup = null;
DataBackup = new HashMap<String, Object>();
...... Data Save Working.....
return DataBackup;
}
- 'OnCreate ()' call back, Data Loading.
: 'Public void onCreate (Bundle savedInstanceState)' call back, 'Data Loading' job is.
public void onCreate(Bundle savedInstanceState) {
....
Object obj = getLastNonConfigurationInstance()
if (obj != null) {
HashMap<String, Object> DataBackup = (HashMap<String, Object>) obj;
..... Data Loading .....
}
....
}
3. AVD(Android Virtual Device) Horizontal / vertical mode switching Tip
: Android aemyulreyiteoin AVD (Android Virtual Device) of the 'horizontal and vertical' transition [CTRL] + F11 or [CTRL] + F12 and pressed, the screen 'aspect' is turned into.
※ While pressing the Control key and continue pressing the key until you change aneuni attention.
: Function Key
[CTRL] + F11
[CTRL] + F12
On the numeric keypad [7] (numeric keypad [7] [NumLock] can be off work)
4. Screen rotation
1) Android 2.1 -Eclar
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = display.getOrientation();
=> orientation == 0 : Vertical Mode
=> orientation == 1. Horizontal Mode
2) Android 2.2-Froyo
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int rotation = display.getRotation();
=> Surface.ROTATION_0 : Vertical Mode
=> Surface.ROTATION_90 : Horizontal Mode
=> Surface.ROTATION_180 : Vertical Mode
=> Surface.ROTATION_270 : Horizontal Mode
In addition, inquiries, or questions, please contact us.
(joonryang@gmail.com)
[Android강좌][Korean][테마] - screenOrientation / Rotation
Android 'Rotation / screenOrientation' 에 관련된 내용을 하나씩 살펴보자.
1. screenOrientation
(1) 'Xml' 설정
: “AndroidManifest.xml” 에서 Activity Tag 에 "android:screenOrientation"을 설정하면 된다.
- portrait : '세로'만 보기
- landscape : '가로'만 보기
- norsensor : '가로/세로' 모두 전환 X
- sensor : '가로/세로' 모두 전환 O
=> 단점 : 폰의 '설정-시스템-디스플레이-자동화면 회전' 기능과 무관하게 동작한다.
즉, '자동화면 화전'을 'Diable'로 설정하더라고 회전이되는 것이 문제다.
- unspecified : '가로/세로' 모두 전환 O
=> 특징 : 폰의 '설정-시스템-디스플레이-자동화면 회전' 기능에 따라 동작한다.
즉, '자동화면 화전'을 'Diable'로 설정한다면 회전이 동작하지 않는다.
(2) 'Code' 설정
: Code 상에서 “setRequestedOrientation()” API를 사용하면 된다.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
...ETC...
2. 'Rotation' 주의 사항
: 안드로이드는 화면 회전 기능을 지원한다.
하지만, 아무런 설정이 없다면, 회전 할 때마다 기존에 있던 Activity의 Data를 보존하지 않는다. 즉, 가로/세로 전환 시에 UI가 새로 그려지면서 Activity의 onDestroy()와 onCreate()가 수행되기 때문이다.
1) 'onDestroy() & onCreate()' 다시 로딩하지 않는 방법
- 'AndroidManifest.xml' 설정
: android:configChanges="keyboardHidden|orientation"
- 'Code' 설정
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
switch(newConfig.orientation) {
case Configuration.ORIENTATION_PORTRAIT:
.....working......
break;
case Configuration.ORIENTATION_LANDSCAPE:
.....working......
break;
}
}
: Activity가 다시 로딩되지 않기 때문에 화면의 크기는 변하지 않는다. 그러므로 'Code' 부분에서 위의 작업을 해주어야 한다.
2) 'onDestroy() & onCreate()' 호출 시, Data Backup 방법
- 화면 회전 시, Data Save.
: 'public Object onRetainNonConfigurationInstance()'에 화면 회전시, 데이터를 저장하는 코딩을 한다.
public Object onRetainNonConfigurationInstance() {
HashMap<String, Object> DataBackup = null;
DataBackup = new HashMap<String, Object>();
...... Data Save Working.....
return DataBackup;
}
- 'onCreate()' 다시 호출 시, Data Loading.
: 'public void onCreate(Bundle savedInstanceState)' 다시 호출 시, 'Data Loading' 작업을 한다.
public void onCreate(Bundle savedInstanceState) {
....
Object obj = getLastNonConfigurationInstance()
if (obj != null) {
HashMap<String, Object> DataBackup = (HashMap<String, Object>) obj;
..... Data Loading .....
}
....
}
3. AVD(Android Virtual Device) 가로/세로 모드 전환 Tip
: 안드로이드 애뮬레이터인 AVD(Android Virtual Device)의 '가로/세로' 전환은 [CTRL] + F11 또는 [CTRL] + F12를 누르면, 화면이 '가로/세로'로 전환된다.
※ 컨트롤 키를 계속 누른상태에서 키를 계속 누르면 바뀌지 않으니 주의.
: Function Key
[CTRL] + F11
[CTRL] + F12
숫자키패드의 [7](숫자키패드의 [7]은 [NumLock]이 꺼져 있어야 작동 가능)
4. 화면 회전 각도
1) Android 2.1 -Eclar
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int orientation = display.getOrientation();
=> orientation == 0 : 세로
=> orientation == 1. 가로
2) Android 2.2-Froyo
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int rotation = display.getRotation();
=> Surface.ROTATION_0 : 세로
=> Surface.ROTATION_90 : 가로
=> Surface.ROTATION_180 : 세로
=> Surface.ROTATION_270 : 가로
추가로 문의 사항이나, 궁금한 점이 계시면 연락주세요.
(joonryang@gmail.com)
※ 도움이 되셨다면, ^^. 맨 위 광고클릭 좀..ㅎㅎ
피드 구독하기:
글 (Atom)