Monday, June 11, 2012

Difference between a View"s Padding and Margin

What is the difference between a View's Margin and Padding?

Source: Tips4all


  1. Padding is the space inside the border, between the border and the actual view's content. Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent).

    Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object. Note that, like the padding, the margin goes completely around the content: there are margins on the top, bottom, right, and left sides.

    An image says more than 1000 words:

  2. Padding is inside of a View.

    Margin is outside of a View.

    This difference may be relevant to background or size properties.

  3. Padding is within the view, margin is outside. Padding is available for all views. Depending on the view, there may or may not be a visual difference between padding and margin.

    Whether or not margin is available, on the other hand, is determined by the container of the view, not by the view itself. In LinearLayout margin is supported, in AbsoluteLayout - no.

  4. This may be helpful

    Declaring Layout