How to include layout inside layout?

前端 未结 6 781
执念已碎
执念已碎 2020-12-12 20:24

How to include layout inside layout in Android?

I am creating common layout. I want to include that layout in another page.

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 20:36

    Note that if you include android:id... into the tag, it will override whatever id was defined inside the included layout. For example:

    
    

    yourlayout.xml:

    
       

    Then you would reference this included layout in code as follows:

    View includedLayout = findViewById(R.id.some_id_if_needed);
    Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);
    

提交回复
热议问题