0

I have a TextView with android:paddingRight and I want to support API 14

        <TextView
            android:id="@+id/account_name"
android:paddingEnd="@dimen/account_menu_chevron_size_plus_margin"
            android:ellipsize="end"
            android:gravity="center_vertical"
            android:lines="1"
android:paddingRight="@dimen/account_menu_chevron_size_plus_margin"/>

I want to create two layouts (RTL and LTR).

I saw this post about LTR and RTL drawables

but how would I do the merge and folders for layouts xml?

Paebbels
  • 15,573
  • 13
  • 70
  • 139
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • Could you clarify what is your question? Do you want to have padding on the same side for both directions or do you want to have it changed? There is rarely need for separate layouts for both directions – Ernest Zamelczyk Oct 04 '18 at 08:20
  • yes, i have added the code. sorry – Elad Benda Oct 04 '18 at 08:29
  • according to the android documentation if you want RTL support below API 17 you have to add android:paddingRight also with the android:paddingEnd and parallelly I don't think so you have to create two layouts for this. Please add images with regards to your problem for better understanding. – yashkal Oct 04 '18 at 08:44
  • but what happens for API 14 and rtl when it ignores paddingEnd? then i need to align to paddingLeft ? – Elad Benda Oct 04 '18 at 08:46

1 Answers1

0

If you want to have padding on the right regardless of the direction of the layout you should use paddingRight but if you want to have padding on the right for ltr layout but on the left fot rtl layout you should use paddingEnd.

The same applies for margins and constraints in ConstraintLayout

Ernest Zamelczyk
  • 2,562
  • 2
  • 18
  • 32
  • yes, but I want to support API level 14. TextView attribute – Elad Benda Oct 04 '18 at 08:34
  • As mentioned [here](https://android-developers.googleblog.com/2013/03/native-rtl-support-in-android-42.html) if you're targeting API below 17 you should use both attributes `start` and `left` with `end` and `right` – Ernest Zamelczyk Oct 04 '18 at 08:46
  • but for api14 android ignores "end" and i need to choose left(rtl) and right(ltr) – Elad Benda Oct 04 '18 at 08:47
  • Yes. My suggestion is to target api 17+ since only 1.7% of all Android devices are on below that. It's not worth the work you would need to put into it. – Ernest Zamelczyk Oct 04 '18 at 08:52
  • Yeah I don't think you should be worried about that. Even the android system itself doesn't support RTL layout before api 17. The only way you could implement that is make separate layout for each configuration and then based on locale serve that layout. Something like BaseActivity and BaseFragment having two abstract methods like `provideLayout` and `provideRtlLayout`. And they would decide which one to inflate. – Ernest Zamelczyk Oct 04 '18 at 09:22