Reputation: 77
When I want to change the direction of layout to right if I assign android:gravity="right"
I will give the same result as when I assign android:layoutDirection="rtl"
.
I want to know the difference between two of them.
Upvotes: 1
Views: 969
Reputation: 1712
rtl
means "right to left"
, you would use android:layoutDirection="rtl"
if you wanted a view group to display content specifically for right to left languages (always) like Arabic. This is why it is aligning your view to the right. That said, I would recommend that you shy away from ever using layoutDirection
since it overrides whatever the locale of the device is.
android:gravity="right"
will align a view to the right. I also recommend that you don't use this (or gravity="left"
) because it will not adjust for rtl
languages, so if you ever release an Arabic version of the app the layout will look odd for your Arabic users.
Instead you should use android:gravity="end"
as this will align your view right in ltr
languages (English) and left in rtl
languages (Arabic). You need to have a minSDK>17
to use end and start alignments, but I am assuming you are because you also need a min sdk of 17 to use layoutDirection
.
Upvotes: 1
Reputation: 9733
This is RTL(Right to left) Layout. Everything is aligned from right to left for those who know Urdu or Arabic.
layout_gravity = "right"
align your view to right of parent. Refer the image. Only TextView is aligned to right and everything else is left to right.
Upvotes: 0