2011-11-27 88 views
0

我有以下代码:问题追加表行表的布局

HashMap<String, String> tip = venue.tips.get(j); 
      TableRow tr = new TableRow(this); 
      TableRow.LayoutParams tableRowParams = 
        new TableRow.LayoutParams 
        (TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.WRAP_CONTENT); 
      tr.setLayoutParams(tableRowParams); 

      LinearLayout ll = new LinearLayout(this); 
      ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 

      TextView tips = new TextView(this); 
      tips.setText(tip.get("text")); 
      Log.v("TIPS TEXT", tip.get("text")); 
      tips.setLayoutParams(new LayoutParams(
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 

      ImageView avatar = new ImageView(this); 
      avatar.setImageBitmap(getBitmapFromURL(tip.get("photo"))); 
      Log.v("PHOTO URL", tip.get("photo")); 
      avatar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

      ll.addView(tips); 
      ll.addView(avatar); 

      tr.addView(ll); 

      View v = new View(this); 
      v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1)); 
      v.setBackgroundColor(Color.rgb(51, 51, 51)); 

      tipsTable.addView(tr,new TableLayout.LayoutParams(
         LayoutParams.FILL_PARENT, 
         LayoutParams.WRAP_CONTENT)); 
      tipsTable.addView(v); 

我觉得我做错了什么事与建立布局,但现在的问题是,我不能看到行加入到tipsTable。为什么是这样?

回答

0

你不打电话setContentView()任何地方。您创建此布局但从不将其分配给活动。我想你想要做的是你已经设置了所有的布局东西后:

setContentView(ll); 
+0

这样做,让我错了 – xonegirlz

0

沿着相同的路线:tipsTable似乎是你俯视所以尽量的setContentView(tipsTable)