Wow, this is very interesting! Thanks to the following article:
http://www.doubleencore.com/2013/05/layout-inflation-as-intended/
Basically, if you inflate a layout without parent specified, all layout_xxx
attributes specified within the root of the layout xml are discarded. You should inflate your layouts as
inflater.inflate(R.layout.your_layout, parent, false);
Also, note that if you pass true (attach to root), the returned element will be the parent element provided. Pay attention to this as it may cause problems when you're expecting the inflated layout to be returned!