2013-04-27 74 views
0

它只顯示1列。我想在tableRow中動態添加2列而不使用另一個for循環。它只顯示1列。我想在tableRow中動態添加2列而不使用另一個for循環。動態設置表格列爲2

 **for (int j = 0; j <= arrtype.size() - 1; j++) { 
     row = new TableRow(this); 
     TableRow.LayoutParams trParams = (new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); 

     String arrnameHolder = arrname.get(j); 
     int imgId = getResources().getIdentifier(arrimage.get(j), 
       "drawable", "com.package"); 
     RelativeLayout rl = new RelativeLayout(this); 
     RelativeLayout.LayoutParams rlParams = (new RelativeLayout.LayoutParams(
       LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
     rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);   

     img = new ImageView(this); 
     img.setLayoutParams(new TableRow.LayoutParams(
       LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
     img.setPadding(10, 10, 10, 10); 
     img.setImageResource(imgId); 
     tv = new TextView(this); 
     tv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
     tv.setText(arrnameHolder); 
     tv.setTextColor(Color.WHITE); 
     // tv.setBackgroundColor(Color.parseColor("#7000")); 
     tv.setLayoutParams(rlParams); 
     tv.setBackgroundColor(color.background_dark); 
     tv.setTypeface(Typeface.DEFAULT_BOLD); 
     tv.setTextAppearance(getApplicationContext(), 
       android.R.style.TextAppearance_Large); 
     tv.setGravity(Gravity.CENTER); 
     tv.setPadding(10, 10, 10, 10); 
     rl.addView(img); 
     rl.addView(tv); 
     row.addView(rl); 

     table.addView(row); 
    } 
    scroll.addView(table); 
    layout.addView(scroll, scrollParam); 
}** 

回答

1

在錶行中的RelativeLayout代替,使用LinearLayout

此外,沒有必要寫rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);什麼這行是幹什麼的,加上最新的項目表中的底部...

+0

做好@pallvi :) – SagarPPanchal 2013-05-13 12:07:58