2011-10-10 32 views
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); 
    } 



} 

}的LayoutParams未示出

在上面的代码,如果我删除行edt.setLayoutParams ...编辑文本都出现。 但是,如果我设置他们的参数,他们不显示。 任何想法可能是什么原因?

回答

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); 

希望这将有助于你出来......

+0

日Thnx它的工作我用TableRow.LayoutParams行内。对于每一个元素。 – Gaurav

相关问题