Include layout with custom attributes

后端 未结 7 862
我寻月下人不归
我寻月下人不归 2020-12-02 22:24

I\'m building a complex layout and I want to use include tag for my custom component, like this:



        
7条回答
  •  有刺的猬
    2020-12-02 22:53

    I know this is an old question but I came across it and found that it is now possible thanks to Data Binding.

    First you need to enable Data Binding in your project.

    Then add data binding to the layout you want to include:

    
    
    
        
    
    
    
    ...
    
    
    
    ...
    
    
    
    

    Finally, pass the variable from the main layout to the included layout like this:

    
    
    
        ...
        
    ...
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...
    
    ...
    
    

提交回复
热议问题