歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> TableRow動態添加組件時遇到的問題

TableRow動態添加組件時遇到的問題

日期:2017/3/1 10:39:23   编辑:Linux編程
  1. public class Main extends Activity {
  2. ScrollView scroll;
  3. TableLayout tl1;
  4. public void onCreate(Bundle savedInstanceState){
  5. super.onCreate(savedInstanceState);
  6. this.setContentView(R.layout.main);
  7. tl1 = (TableLayout)this.findViewById(R.id.tl1);
  8. TableRow tr = new TableRow(this);
  9. tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  10. TextView tv = new TextView(this);
  11. tv.setText("tex");
  12. tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  13. tr.addView(tv);
  14. tl1.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
  15. }

敲代碼時,如果直接敲LayoutParams這個類的話,默認導入的包是Android.view.ViewGroup.LayoutParams;

如果導入了這個包,實際上在Activity中是無法正常顯示要加入的View組件的

真正要導入的包是android.widget.TableRow.LayoutParams;不過這個包在Eclipse中並沒有提示出來,裝了ADT15依然沒有提示。

Copyright © Linux教程網 All Rights Reserved