private LinearLayout layout;//创建一个布局
layout = mLayout = (LinearLayout) findViewById(R.id.layout);
TextView text = new TextView(MainActivity.this);
text.setText("往layout中添加TextView");
//设置LinearLayout的参数,(宽,高)
LinearLayout.LayoutParams p =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(text,p);//往layout中添加TextView