Why LinearLayout's margin is being ignored if used as ListView row view

The fact is that, the margin of LinearLayout (child) asks its parent layout (container) to give child layout a margin of x value.

So if the parent layouts' LayoutParams support the margins then that margin is honored and applied.

ListView uses AbsListView.LayoutParams by default, which doesn't include any margin support, just the height and width, thats why, it simply ignores the params value for margins.

Whereas other layout params like ActionBar.LayoutParams, FrameLayout.LayoutParams, GridLayout.LayoutParams, LinearLayout.LayoutParams and RelativeLayout.LayoutParams are child of ViewGroup.MarginLayoutParams, which honors the child's margin values.

Tags:

Android