What is the difference between marginStart/marginLeft and marginEnd/marginRight?

Asked

Viewed 122 times

1

I know that this doubt is quite simple, but I have already searched and still not found an answer that was satisfactory to me. After all the marginLeft is not equivalent to marginStart? And it wouldn’t be the same for the marginEnd and the marginRight? I wonder if someone could explain to me the difference between these properties XML android?

1 answer

5


The big difference between them is only perceived in devices using some language that requires reading RTL (Right to Left) and not LTR (Left to Right) as we are used.

It is possible to force this view using developer settings, but it is not very common to use this.

RTL support only appeared completely on Android 4.2, but already had a basic support on Android 4.1, this post can help understand.


Returning to the question, the marginStart and marginEnd, as well as the paddingStart and paddingEnd will generate the same result if the device is in LTR as its fixed attributes: marginLeft, marginRight, paddingLeft and paddingRight respectively, but if the device is in RTL will be exactly the opposite.

When you use marginLeft, is applying the left (fixed) margin of the element in the LTR view. Using marginStart, this margin applies to the (relative) start. In the case of the LTR view it is the left of the element, but in the case of the RLT it is the right of the element.

My suggestion is to always use the relative attributes in your case minSdkVersion is greater than 17 (Android 4.2). If your minSdkVersion is less than 17, always use both together with the same values. e. g: marginLeft and marginStart.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.