import xml into another xml

后端 未结 4 1486
后悔当初
后悔当初 2020-12-12 17:29

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

4条回答
  •  既然无缘
    2020-12-12 17:36

    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!):

    
    
        
    
    
    

提交回复
热议问题