- 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依然沒有提示。