I have lots of control repeated in my xml
(a Button
for instance). Is there any possibility to write the Button
once in a xml
You can use the default include
XML tag to include an external layout:
This layout should have an outside ViewGroup
that encapsulates the content or a merge
tag to avoid having to use an unnecessary layout:
Also, if you need a better way to include pieces of layout that acts like a container (a custom ViewGroup
), you can use this custom ViewGroup. Note that this does not import an XML into another XML file, it inflates the content from the external layout and replaces into the view. It's similar to ViewStub
, a "ViewGroupStub" like.
This lib acts as if the ViewStub
could be used as following (note that this example does not work! ViewStub
isn't a ViewGroup
subclass!):