본문 바로가기

안드로이드 Android

[모바일프로그래밍] 9-1 리소스 관리

프로젝트에서 drawable 디렉토리 우클릭 → New → Drawable resource file → Available qualifiers에서 Locale 선택

원하는 언어 및 국가 선택
같은 파일 이름으로 다른 언어 및 국가를 선택하여 생성
temp.xml 중 하나라도 삭제하면 다른 디렉토리의 temp.xml도 삭제됨
좌측 상단에 Android라고 돼 있던 부분을 Project로 바꿈

세 디렉토리에 각각 다른 사진을 같은 이름으로 바꿔서 넣어 준다.

다시 Android로 이동

cats라는 디렉토리가 생성되고 세 가지 이미지가 모두 들어 있다.

 

프로젝트에서 res 우클릭 → New → Android Resource Directory Available qualifiers에서 Locale 선택

아까와 똑같이 언어 및 국가를 다르게 선택해 두 가지를 만든다.

좌측 상단을 통해 Project로 바꾸면 values 디렉토리 두 종류가 추가로 생성된 것을 확인할 수 있음

values\string.xml

<resources>
    <string name="app_name">My Application</string>
    <string name="text">My Sightseeing Area</string>
</resources>

en\strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Sightseeing Application</string>
    <string name="text">US Sightseeing</string>
</resources>

ko-rKR\strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">관광명소 소개</string>
    <string name="text">남대문 관광명소</string>
</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.2" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="248dp"
        android:layout_height="221dp"
        android:layout_marginStart="80dp"
        android:layout_marginTop="120dp"
        android:scaleType="fitXY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.161"
        app:srcCompat="@drawable/cats" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="108dp"
        android:layout_marginTop="48dp"
        android:text="@string/text"
        android:textSize="24sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />
</androidx.constraintlayout.widget.ConstraintLayout>

디바이스의 설정에서 언어 우선순위를 변경