[Android] 대체 Resource Android 2011. 12. 16. 14:43

대체 리소스란 그 환경이 변함에 따라 대체 한다는 의미이다.

예를 들어 화면을 회전 하였을 경우 거기에 맞게 변화하게 된다.

여기에서 기본 적으로 가로 형태를 돌렸을 경우 -land 폴더를 찾아가고 -port 경우는 세로이다.

-port 가 없을 경우에는 layout 폴더를 참조를 한다.

먼저 res/layout-land 폴더를 만들고 layout 내의 xml과 동일한 내용을 적용을 시켜보자 코드는 다음과 같다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    >
    <Button
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="1번"
        />
    <Button
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text="2번"
        />
</LinearLayout>

이 코드를 실행하여 에뮬레이터에서 Ctrl + F11 을 누르면 화면의 방향이 변하는데 이를 실행함서 그 내용을 확인 할 수 있다.