`
android_madness
  • 浏览: 39449 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

动态添加tableview

阅读更多
        TableLayout table=(TableLayout)findViewById(R.id.shoppingCartTable);  

        table.setBackgroundColor(Color.BLACK);
        TableLayout.LayoutParams params=new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
        		TableLayout.LayoutParams.WRAP_CONTENT); 
        params.leftMargin =1;
        params.rightMargin =1;
        params.topMargin =1;
        params.bottomMargin =1;
        TableRow.LayoutParams params2 =  new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
        		TableRow.LayoutParams.WRAP_CONTENT); 
        params2.leftMargin =2;
        params2.rightMargin =2;
        params2.topMargin =2;
        params2.bottomMargin =2;
        
        for(int i=0;i<20;i++){//20  
            TableRow row=new TableRow(this);  
            row.setLayoutParams(params);  
            row.setBackgroundColor(Color.BLUE); 
            row.setPadding(1, 1, 1, 1);
            
            for(int j=0;j<1;j++){//1  
                TextView col=new TextView(this);  
                col.setLayoutParams(params2);
                col.setText("i="+i);  
                col.setTextColor(0xFFFF0000); 

                row.addView(col);//  
            }  
            table.addView(row);//  
        } 


这一段动态添加tableview的代码,保留下来以后说不定用的到
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics