Margin
property represents the distance between the element and its adjacent elements and is used to control the element’s rendering position, and the rendering position of its neighbors. Margin can be specified onLayout
andView
classes.Padding
property represents the distance between anElement
and the child elements of it and thus it is used to separate the control from its own content.Padding
values can be specified onLayout
classes.
Suppose, two adjacent elements have a margin of value 20 pixels assigned, what will be the distance between these two elements? Why?
The distance between two elements will be 40 pixels in this case, because, Margin
property values are Additive
. In addition to this, if Margin
and Padding
both are applied, then the distance between element and its content will be Margin + Padding
.