Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does margin override marginLeft in Android (same with radius, etc)?

This makes no sense to me, coming from CSS. In CSS, if you specify a margin and then margin-left, the left margin will assume the more granular value.

In Android, it is the opposite. Same goes for android:radius, and I'm sure other values.

My question is: why?.. It makes no sense. Is there a single reason for doing it this way?

Edit: prompted by trying to find a solution to yet another Google ADT/Android bug http://code.google.com/p/android/issues/detail?id=7588

like image 381
Artem Russakovskii Avatar asked Nov 11 '10 02:11

Artem Russakovskii


People also ask

How does padding of a view differ from the view's margin?

Cool, so margin means the space outside the view, however padding means the space inside the view.

What happens when margin Auto is applied on a span of fixed height width?

When you have specified a width on the object that you have applied margin: 0 auto to, the object will sit centrally within it's parent container. Specifying auto as the second parameter basically tells the browser to automatically determine the left and right margins itself, which it does by setting them equally.

How do you set margins in layout parameters?

The basic idea is to get margin out and then update it. The update will be applies automatically and you do not need to set it back. To get the layout parameters, simply call this method: LayoutParams layoutParams = (LayoutParams) yourView.

How does auto margin work?

The auto ValueYou can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.


1 Answers

I have had the same frustration, but if you think about it, which value should be used? I know in your post you say that CSS uses the "more granular value" but it all boils down to pixels in the end and the result is simply two pixel values that need to be chosen between. The CSS standard chose to do it one way, Android chose the other, I don't think either approach is wrong, they are just different.

like image 107
CaseyB Avatar answered Sep 19 '22 15:09

CaseyB