0
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayout);



   for(int k=0;k<10;k++)    
   {    TableRow tr=new TableRow(this);
       tr.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
        tr.setId(k);

    for(int s=0;s<10;s++)
         {
         EditText edt=new EditText(this);
         Log.i("SS","setting layout params for textview "+s+k);
         edt.setText("abc "+s+k+"  ");


        edt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        ViewGroup.LayoutParams p=edt.getLayoutParams();

         Log.i("SS","edt params "+p.height +" "+p.width);
        tr.addView(edt);
         }
   ll.addView(tr);
   }



}

}

在上面的代码中,如果我删除行 edt.setLayoutParams... 正在显示编辑文本。但是,如果我设置他们没有显示的参数。知道可能是什么原因吗?

4

1 回答 1

0

试试这个...

TableRow tr = new TableRow(this);  
TableLayout.LayoutParams tableRowParams=
  new TableLayout.LayoutParams
  (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);


tableRowParams.setMargins(10, 10, 10, 10);

tr.setLayoutParams(tableRowParams);

希望这会帮助你...

于 2011-10-10T04:33:03.380 回答