在我的 android 项目中,我有一个表格视图,我想动态添加一些图像按钮。所以我这样编码
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
TableRow rows = new TableRow(this);
rows.setBackgroundColor(Color.parseColor("#eaeaea"));
rows.setId(4500+id);
ImageButton btns=new ImageButton(this);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            params1.leftMargin = 10;
            params1.bottomMargin = 10;
            btns.setBackgroundResource(R.drawable.accept);
            btns.setId(id);
               btns.setOnClickListener(new OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       int id=v.getId();
                       setFlag(id);
                   }
               });
LinearLayout childLayout = new LinearLayout(context);
childLayout.addView(btns);
rows.addView(childLayout);  
table.addView(rows);
它工作正常。但图像按钮的数量可能会有所不同。有时 5-10 个按钮那个时候所有的按钮都显示在一行中。我想根据像图像的按钮来扩展线性布局和表格布局。

有什么想法吗?
我是android新手,请帮忙
提前致谢