Wednesday, October 17, 2018

How to set layout attributes on an included layout

If you're using the tag to include parts of a layout into another layout you might also want to be able to add layout attributes to them. For example, in a RelativeLayout you might want to say that whatever you include will be below some other view. Or in a ConstraintLayout you might want to set the constraint rules on that included layout.

Turns out that even if the layout you include has layout_width and layout_height in order for android to honor the layout params that you are giving your include you need to set layout_width and layout_height within the tag.