表格布局和表格行

时间:2012-08-07 07:21:02

标签: android android-layout android-tablelayout

我需要动态创建六个textview但是一个条件每个表行只有三个textview我需要放置两个表行并且每个地方放置三个textview

1 个答案:

答案 0 :(得分:0)

尝试这样的事情。

    TableLayout myTable=new TableLayout(this);        
    TextView[][] myTextView=new TextView[3][3];
    myTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    TableRow[] myRow=new TableRow[3];        
    for (int i = 0; i < 3; i++) {
        myRow[i]=new TableRow(this);
        myRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));           
        for (int j = 0; j < 3; j++) {               
            myTextView[i][j]=new TextView(this);  
            myTextView[i][j].setText("Your Text");
            myRow[i].addView(myTextView[i][j]);
        }   
        myTable.addView(myRow[i]);
    }
    LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
    lin.addView(myTable);