153

What is difference between Android margin start and right (or margin end and left)?

It is trivial question, but I cannot seem to learn from the documention what is difference between view start/end and left/right. It could be that I just don't understand something, but I cannot make any progress with this at all.

Cat
  • 66,919
  • 24
  • 133
  • 141
Chameleon
  • 9,722
  • 16
  • 65
  • 127

3 Answers3

216

For left-to-right flow, start=left, end=right.

For right-to-left flow, start=right, end=left.

The "start" and "end" concepts were added in API Level 17, as part of Android 4.2's support for RTL layouts.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 6
    Do you know which one takes precedence if they are different? (curiosity). like `marginLeft=1` `marginStart=2` (in a Left2Right Scenario for example) – Martin Marconcini Jun 11 '15 at 17:32
  • 1
    @MartínMarconcini: Hopefully start/end take precedence, but I don't know that for certain. You'd have to try it. – CommonsWare Jun 11 '15 at 17:33
  • @Martin For what I understood, left/right is ignored when start/end exists above API 17. However, I can't see why your left/right would differ from start/end; I'm curious. – Liggliluff Feb 05 '17 at 14:19
  • 3
    @Liggliluff bugs, typos, etc :) After API 17 start/end take precedence and there's a LINT warning if you still use the old ones. They are ignored, I tried. – Martin Marconcini Feb 06 '17 at 23:12
  • @Martin Thanks for testing it out. Are both left/right ignored if only one of either start or end shows up? (Wouldn't make much logical sense to use start/right when those will be the same for RTL scripts). – Liggliluff Feb 08 '17 at 02:12
  • You're taking this test to 11 @Liggliluff :) I didn't do THAT much testing. I use start/end (API 17+) in my current project, so I went ahead and modified that to try if a different left was ignored and it appears to have been. But For further testing you may want to file -> new project and experiment from there :) – Martin Marconcini Feb 08 '17 at 17:51
  • marginStart and marginEnd have precedence in LTR whereas marginLeft and marginRight have precedence in RTL layout – Faisal Khalid Jan 31 '18 at 04:11
46

Android supports RTL layouts from API 17+ i.e., Android 4.2 (Jelly Bean).and when we make our layout to support both RTL and LTR then we can not use layout_marginleft and layout_marginRight there we use layout_marginstart and layout_maginend .

pic

Avnish Nishad
  • 1,634
  • 1
  • 17
  • 18
0

If you are familiar with languages like Arabic or Urdu you will be aware that they start from right to left unlike English where we read from Left to Right.

So if we set margins using Margin right/left then we don't care about the language but we just directly add the margin according to the universal left and right.

But if we use Margin start/end then we care about the language. So let's say if the app has a UI which is written in Arabic language then the start will be the right side and if the UI is in English the start will be on the left side.

Now when to use right/left and when to use start/end :

So if you are sure that your app is going to have no language needs and you need to show your UI from left to right always like in English language then you can opt for left/right margin as it's easy and simple to understand. But if you are building a multi lingual app then you can opt for start/end margins as you don't have to create multiple UI's.

oyeraghib
  • 878
  • 3
  • 8
  • 26