Reputation: 24484
When I use include
in a layout, I have to set width and height both to include
tag and to the layout it is linked to. Otherwards it won't work correctly. So, it seems, that include
is not a link, but a subclass of View, if it has its own width, height, id and so on. But on developer's site there is not such class as include
. Who are you, Mr. include
?
Upvotes: 1
Views: 59
Reputation: 36045
The <include>
tag can be thought of as a copy/paste of the internal layout. It's part of the xml parsing that's in the View Inflater
classes. It effectively takes the layout ID, inflates the xml object you pass in, then adds it to the main layout that it's inflating based on the attributes of the included layout. You can use it on anything that inherits from View
.
You can overwrite any of the attributes that have layout_
in them. You don't have to overwrite the width and height attributes if they are included in the root of the layout your including. However, you do have to overwrite those parameters if you are overwriting any other attribute. It's part of a bug in how <include>
is parsed. If you want to change, say, layout_marginLeft
, you would have to overwrite layout_width
and layout_height
to the same values that are in the layout in order for the parser to overwrite the left margin attribute.
Upvotes: 3
Reputation: 8176
include
doesn't actually need a width and height if you specify the width and height of the root element of the included layout. In other words, this is entirely valid:
<include layout="@layout/my_included_layout" />
So long as my_included_layout
has a root element with a width and height it will be happy.
Upvotes: 1