4

I was making a xml file and was applying gravity to make view content to shift it to extreme right side of window but i saw gravity as right and end.So, what is the actual difference between the both and which one to use where.

Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37
  • 2
    Left and right are quite literally that. If, however, you are going to support different conventions for language etc then you need to deal with LTR (left to right) or RTL (right to left) concepts. In the case of LTR the 'left' and 'start' mean the same thing and 'right' and 'end' also the same thing. The reverse is true for RTL where 'right' and 'start' are the same and 'left' and 'end' are the same. In other words, if you want to cater for both LTR and RTL then you should use 'start' and 'end' for positioning certain things. – Squonk Oct 09 '14 at 19:07

3 Answers3

6

in Arabic, Persian and all rtl (Right-To-Left) Locales, end is left but for English and other ltr (Left-To-Right) Locales end means right

Sepehr Behroozi
  • 1,780
  • 1
  • 17
  • 32
1

Left and right gravities might not work correctly in applications localized for right-to-left languages like Hebrew, Arabic etc. In those languages left and right sides are mirrored to european languages. If you use hardcoded left and right gravities for some elements of your UI, then they might be misplaced in right-to-left localizations. If you use begin and end, then Android will map them correctly to left or right depending on current system language. Thus begin for English is equal to left and for Hebrew to right etc.

If you app has a localization for one of right-to-left languages, then you should always use begin and end. Otherwise you can safely stay with left and right.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
0

In my opinion when we set android:orientation="horizontal" in the main layout, then it's better to set gravity of its child as start and end to make it more effective with the layout. BUT when other orientations are used then we can use other gravity forms as well.

Harneev
  • 544
  • 4
  • 12