paddingLeft vs paddingStart

19 Mar

So, in the last few days, several teammates have asked me what is the difference between paddingLeft and paddingStart. So, I have written this to document my experience.

Why use paddingStart?

paddingRelative, paddingStart and paddingEnd are added in API 17 to support RTL devices. When your phone is switched to a RTL language, every view should be a mirror image of LTR mode.

In a LTR language, paddingStart is on the left and paddingEnd is on the right. In a RTL language (Arabic, Hebrew), it’s the opposite. If you only define paddingLeft and paddingRight and not start and end, then the layout would not be a mirror image in a RTL phone.


LTR language phone


RTL language phone


When to use paddingStart?

paddingStart and paddingEnd are equivalent to paddingLeft and paddingRight in API 17+ devices. Remember to add paddingStart and paddingEnd in these situations:

  • When paddingLeft and paddingRight are different.
  • Your app needs to support API 17+ devices with RTL.


How to use paddingStart and paddingEnd?

  • If paddingLeft and paddingRight are the same, you are done.
  • Otherwise, wherever you see a paddingLeft, put a paddingStart with it, same for right-end.
  • Do not remove paddingLeft and paddingRight from xml file (until the day we decide we will stop supporting API 16- devices).
        android:paddingLeft="@dimen/start_padding" />


I used paddingStart and paddingEnd and now QA tells me that my padding is broken in ICS/JB devices.

RTL support is added in API 17, so it’s still necessary to define paddingLeft and paddingRight in your xml. paddingStart and paddingEnd will override those values in API 17+ device.

Ok, it fails the lint test. Are you lying to me?

As I have said in “Why use paddingStart?”, paddingStart (etc) are added in API 17. So it’s normal for lint test to fail. Here’s a few solutions:

  • Equal left and right paddings
    • If left padding is equal to right padding, then we don’t need to define start and end paddings.
  • Suppress the lint error
  • Have a separate style file
    • Define a values-v17 folder
    • Place start and end in values-v17
    • Keep left and right in values.
Leave a comment

Posted by on March 19, 2016 in Android App, Uncategorized


Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: