Understand Android layout internals

Here is the documentation page from Android

A layout object is a view group

..attributes are considered "layout parameters," which are attributes that describe certain layout orientations of the View object, as defined by that object's parent ViewGroup object.

A layout may obligate each view object (the 5) some characteristics that tells the parent layout the desired behavior for that view object.

So these parameters will apply irrespective of the type of the view object. So the contract of the layout is defined by the parent layout object and not individual member view.

This means even future views that are not yet built are expected to carry, albeit a hash table, of these layout parameters.

Not only that even an existing view may participate in multiple layouts. Depending on which layout it is participating the XML allowed for the layout parameters is controlled by the parent layout.

Each layout is a viewgroup


class LinearLayout.LayoutParams 
    extends ViewGroup.LayoutParams
class RelativeLayout.LayoutParams
    extends ViewGroup.Layoutparams

....
etc.

layout_width
layout_height

actual pixels
density independent pixels: dp
match_parent
wrap_content

getWidth
getHeight
getLeft (relative to parent x position)
getTop (relative to parent y position)
getRight
getBottom

getMeasuredWidth
getMeasuredHeight

setPadding
getPadding

Margin is outside of a view and padding in side of a view for html

Margin can be controlled by viewgroup margin layout params


layout_marginTop
layout_marginBottom
layout_marginLeft
layout_marginRight

This class is inherited from LayoutParams. All subsequent derivations like LinearLayoutParams are extending this one with margins. So most of the layouts get margins.