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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With