Reputation: 109
I was trying to set the padding of a LinearLayout
in XML layouts of Android.
But it gives me 2 options - paddingLeft
and paddingStart
.
What are the differences, and is one the more correct/better attribute to use?
I want the best answer, because this needs the best quality code.
Upvotes: 6
Views: 1827
Reputation: 401
it's all about RTL support, if you choose paddingLeft then when your app operates in RTL Locale eg. Arabic your padding will be reversed. so, using paddingStart and paddingEnd is much more safer when trying to work with RTL world like Urdu or Arabic...etc.
Note : this doesn't matter if you assign the same values for Left and right padding, it obviously will behave the same in LTR and RTL worlds.
Upvotes: 2
Reputation: 20167
The short answer is: paddingStart
is right-to-left (RTL)-aware, which paddingLeft
is not.
You should favor paddingStart
to make your app RTL-friendly, but make sure you test it (there's a developer option to force RTL on in your language, so you don't have to test your app in a language that you can't read).
If the user is in a locale that writes from right to left (RTL), then paddingStart
will be applied on the right side, while if they're in a left-to-right (LTR) locale (such as English), it will be applied on the left side. paddingLeft
, on the other hand, will always be applied on the left, regardless of the locale's text direction.
This is useful, because layouts are often reversed in RTL locales. For instance, a contacts list with contact photos might show the contact photo on the left for LTR locales, and on the right for RTL locales. Since the padding for the photo might be different than the padding for the other side of the item, you'd specify the paddings with paddingStart
(for the photo's padding) and paddingEnd
(for the padding on the other side of the item).
Upvotes: 7