android 在布局中动态添加控件

第一步

Java代码 
  1. final LayoutInflater inflater = LayoutInflater.from(this);  



第二步:获取需要被添加控件的布局

Java代码 
  1. final LinearLayout lin = (LinearLayout) findViewById(R.id.LinearLayout01);  



第三步:获取需要添加的布局(控件)

Java代码 
  1. LinearLayout layout = (LinearLayout) inflater.inflate(  
  2.                         R.layout.listview, null).findViewById(R.id.layout);  



第四步:添加到布局中

Java代码 
    1. lin.removeAllViews();  
    2.                 lin.addView(layout); 
原文地址:https://www.cnblogs.com/Free-Thinker/p/3695093.html