18 Jul 2015

Difference between padding and margin

Padding is used to offset the content of a view by specifying pixels. For example a left padding of 2 wil push views content 2 pixels right side of the left edge. Use android:padding
android:paddingBottom,android:paddingLeft,android:paddingRight,android:paddingTop to set padding on various sides of the content of that view.

Margin specifies the extra space left on all four sides of a view. Margin space is generally outside the view's bounds. To leave space on left side use android:margin_left, to leave space on other sides use android:layout_marginRight, android:layout_marginTop, android:layout_marginBottom etc..

In Simple words .. if you want to take your widget like TextView, EditText far away from other. You should use margin from top,right,left,bottom.

By increasing padding it will increase the inner spacing not making the widget far apart from others..

"Padding is inside of a View.Margin is outside of a View."
This difference may be relevant to background or size properties.
Margin:-
Margins make up the vertical and horizontal areas between elements. If elements have no margins around them, they will bump right up against each other. In other words, he space outside of, or between, elements is what comprises the margin areas.

Padding:-
The padding of an element is the horizontal and vertical space that’s set around the content area of the targeted element. So padding is on the inside of a box, not the outside.



No comments:

Post a Comment