본문 바로가기
프로그래밍/Android

Android에 RTL 적용하기

by 루이마루 2021. 12. 17.

우리나라나 대부분의 나라들에서는 글을 읽을 때 '좌에서 우'로 읽는다. 하지만, 아랍 문화권에서는 '우에서 좌'로 글을 읽는다.

Android에서 다양한 언어를 지원하다 보면 '좌에서 우?' '우에서 좌?' 로 읽게 하려면 어떻게 해야하는지 의문점이 생긴다. 나 역시 앱에서 히브리어를 지원해야 하는 상황에 순간 당황했었었다.

다행히도 Android에서는 RTL(right to left) 미러링 을 지원한다.

미러링!이다. 본인이 만든 앱이 좌우가 거울 처럼 완전히 뒤바뀐다고 생각하면 된다.

 

RTL미러링을 지원하기 위해서는..

 

1. 앱의 build.gradle 에서 target API 는 17 이상에서만 지원한다.

android {
    ...
    defaultConfig {
        targetSdkVersion(17) // Or higher
        ...
    }
}

 

2-1. AndroidManifest.xml의 application 속성에 android:supportsRtl="true"를 추가하면 된다.

<manifest ... >
    ...
    <application ...
        android:supportsRtl="true">
    </application>
</manifest>

 

2-2. AndroidManifest에 추가하지 않고 코드상에 설정하고 싶다면 아래처럼 처리하면 된다.

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
	getWindows().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}

 

2-3. RTL을 앱 전체에 적용하지 않고 일부분에만 적용하고 싶다면 아래처럼 각각의 layout을 xml에서나 code에서 처리를 하면 된다.

 

<xml>

<androidx.constraintlayout.widget.ConstraintLayout
	android:layout_width="match_parent"
    android:layout_height="match_parent"
    .
    .
    android:layoutDirection="rtl"
    >

<code>

 LinearLayout layout=(LinearLayout)findViewById(R.id.layoutrtl);
 layout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

 

 

3. 미러링을 원활하게 적용시키려면 xml 속성을 'left, right'를 'start, end'로 처리해야한다.

기존처럼 left or right 속성을 그냥 사용하게 된다면 정상적인 미러링 화면이 적용되지 않는다.

 

4.  기존 리소스를 건들고 싶지 않다면 layout 리소스를 추가하여 처리도 가능하다고 한다.

res/
    layout/
        main.xml
    layout-ldrtl/
        main.xml

 

 

참고 : https://developer.android.com/training/basics/supporting-devices/languages?hl=ko

'프로그래밍 > Android' 카테고리의 다른 글

Invalid Gradle JDK configuration found. Error  (0) 2022.01.06

댓글