I have few images that looks different on right-to-left. Is it possible to create rtl specific drawable directory or some rtl post-fix for file names to auto-load relevant images? Looks like ldrtl post-fix, added from 17 lvl, is good only for layouts directory.
-
res/layout-ldrtl/ (Right to Left) – Volodymyr Zakharov Jun 26 '22 at 15:32
-
I am taking about Drawables(images), not layouts. – Vitaliy A Jun 27 '22 at 07:43
3 Answers
It's pretty late to answer this question, but I want to share a method that I just found out. I will first recap what is mentioned by the others.
Let's start with a specification.
We need to build something like:
login --> take picture --> win prize
In RTL, it will become:
ezirp niw <-- erutcip ekat <-- nigol
So the big question is how we flip the drawable arrow, let's call it arrow_right.png
:
-->
and in RTL you want it to be like this:
<--
For Android >=19
As others mentioned, we can use the autoMirrored=true
flag. (available from API19)
The usage:
<ImageView ...
src="@drawable/arrow_right"
autoMirrored="true" />
The assets:
├── drawable-xxxhdpi
└── arrow_right.png
├── drawable-xxhdpi
└── arrow_right.png
├── drawable-xhdpi
└── arrow_right.png
├── drawable-hdpi
└── arrow_right.png
├── drawable-mdpi
└── arrow_right.png
Note that:
arrow_right.png
insidedrawable-*
contain-->
Remarks: The only downside is that it's not backward compatible.
For Android <19, Option 1
Like others have pointed out, you can use the ldrtl
option. (doc: Providing Resources)
The usage:
<ImageView ...
src="@drawable/arrow_right" />
The assets:
├── drawable-xxxhdpi
└── arrow_right.png
├── drawable-xxhdpi
└── arrow_right.png
├── drawable-xhdpi
└── arrow_right.png
├── drawable-hdpi
└── arrow_right.png
├── drawable-mdpi
└── arrow_right.png
├── drawable-ldrtl-xxxhdpi
└── arrow_right.png
├── drawable-ldrtl-xxhdpi
└── arrow_right.png
├── drawable-ldrtl-xhdpi
└── arrow_right.png
├── drawable-ldrtl-hdpi
└── arrow_right.png
├── drawable-ldrtl-mdpi
└── arrow_right.png
Note that:
arrow_right.png
insidedrawable-*
contain-->
arrow_right.png
insidedrawable-ldrtl-*
contain<--
.
Remarks: There is nothing wrong with this method, except you need to prepare like 10x assets files. So it leads me to find out the next option.
For Android <19, Option 2
This option will be using the rotationY="180"
attributes. (available from API11)
If you set rotationY="180"
to ImageView
, -->
will turn into <--
.
So we can do something like the following.
The usage:
<ImageView ...
src="@drawable/arrow_right"
android:rotationY="@integer/angle_rtl_180" />
The assets:
drawable
├── drawable-xxxhdpi
└── arrow_right.png
├── drawable-xxhdpi
└── arrow_right.png
├── drawable-xhdpi
└── arrow_right.png
├── drawable-hdpi
└── arrow_right.png
├── drawable-mdpi
└── arrow_right.png
├── values
└── integers.xml
├── values-ldrtl
└── integers.xml
Note:
arrow_right.png
contains-->
values/integers
contains<integer name="angle_rtl_180">0</integer>
values-ldrtl/integers
contains<integer name="angle_rtl_180">180</integer>
Remarks: You only need 1 set of assets, and this solution can be used from API 11, and the usage is simple enough by simply adding android:rotationY="@integer/angle_rtl_180"
.
Hope it helps!

- 3,150
- 29
- 34

- 7,865
- 7
- 46
- 49
-
Very well explained thanks a lot. it worked for me like charm :) – Android is everything for me Sep 27 '18 at 09:43
-
Thanks for explain. if not working than please set rotation as programmatically. – Pratik18 Oct 29 '18 at 08:49
-
1
-
How can I apply the solution For Android >=19 to be in drawable itself to be used in none image views like Button icon or used directly in style drawable? – Muhammad Helmi Dec 09 '19 at 01:43
-
2I tried the solution For Android >=19 for ImageView but it doesn't work for me – Muhammad Helmi Dec 09 '19 at 16:50
For 17+ (4.2.x+) you can use layout direction (ld) resources qualifier, for right to left (RTL) you can use ldrtl and for left to right (LTR) you can use ldltr, e.g. you can use
res/
drawable // Default
drawable-ldltr // LTR
drawable-ldrtl // RTL
Also as any other qualifier you can combine it with many others e.g. drawable-ldrtl-xhdpi
, please note how ldrtl comes before xhdpi otherwise aapt will complain.
And as @Dennis mentioned from 19+ (4.4+) it gets easier as you can use autoMirrored

- 12,863
- 4
- 38
- 34
-
-
@lidkxx Nothing. It was my mistake. `fa` is for Persian language and it's an RTL language. At that time, I meant how should I add these `ldltr` & `ldrtl` to a folder which has this `drawable-fa` name. But now I got it; Just need to create `drawable-ldrtl` for layouts on the Persian language. – Dr.jacky Jan 27 '18 at 08:21
-
-
I find this more useful because i want compeletly different drawable for RTL. – M.kazem Akhgary Oct 28 '18 at 07:58
There's an option to auto-mirror the drawable. Check autoMirrored attribute.

- 2,271
- 6
- 26
- 42
-
I need honeycomb support, auto-mirror is supported only starting from 19 lvl. – Vitaliy A Dec 15 '13 at 14:54