public class Main extends Activity {
ScrollView scroll;
TableLayout tl1;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
tl1 = (TableLayout)this.findViewById(R.id.tl1);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
TextView tv = new TextView(this);
tv.setText("tex");
tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tr.addView(tv);
tl1.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
敲代码时,如果直接敲LayoutParams这个类的话,默认导入的包是android.view.ViewGroup.LayoutParams;
如果导入了这个包,实际上在Activity中是无法正常显示要加入的View组件的
真正要导入的包是android.widget.TableRow.LayoutParams;不过这个包在Eclipse中并没有提示出来,装了ADT15依然没有提示。
From:http://blog.csdn.net/qqii3184/article/details/7193265