How to inflate a layout dynamically?

后端 未结 4 1423
时光取名叫无心
时光取名叫无心 2020-12-18 04:10

I have the following layout defined in XML:


    

        
4条回答
  •  别那么骄傲
    2020-12-18 04:20

    You just need the activity reference and call :

    RelativeLayout relativeLayout = (RelativeLayout)activity.getLayoutInflater().inflate(R.layout.your_layout, null);
    

    Then you can grab the two view using their ids

    relativeLayout.findViewById(R.id.anId);
    

提交回复
热议问题