마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

TableRow내부에 LinearLayout 를 소스코드로 구현하는 방법???

0 추천
TableLayout tl = (TableLayout)findViewById(R.id.table);
       /* Create a new row to be added. */
       TableRow tr = new TableRow(this);
       tr.setLayoutParams(new LayoutParams(
                      LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
            /* Create a TextView to be the row-content. */   
      LinearLayout ll = new LinearLayout(tr.getContext());
      ll.setLayoutParams(new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT));
      ll.setOrientation(LinearLayout.VERTICAL);
      ll.setBackgroundDrawable(shape); 

          TextView data = new TextView(this);
          data.setText("asd");
          data.setBackgroundColor(Color.parseColor("#99cccc"));
          TextView data1 = new TextView(this);
          data1.setText("asd1");
          TextView data2 = new TextView(this);
          data2.setText("asd2");
            /* Add TextView to row. */
            ll.addView(data);
            ll.addView(data1);
            ll.addView(data2);
            tr.addView(ll);
      /* Add row to TableLayout. */
      tl.addView(tr,new TableLayout.LayoutParams(
            LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));

위의 코드를 실행하면 화면에 아무것도 안나옵니다...이유가 뭔지를 모르겠네요...아마도  tablerow내부에 linearlayout이

구현이 되지 않는다고 생각이 됩니다. 구현하는 방법이 없을까요?

skyranger (120 포인트) 님이 2014년 1월 26일 질문

1개의 답변

0 추천
이렇게 수정하니깐 됩니다.
 
TableLayout tl = (TableLayout)findViewById(R.id.table);
      /* Create a new row to be added. */
      TableRow tr = new TableRow(this);
      tr.setLayoutParams(new LayoutParams(
                     LayoutParams.WRAP_CONTENT,
                     LayoutParams.WRAP_CONTENT));
           /* Create a TextView to be the row-content. */   
     LinearLayout ll = new LinearLayout(tr.getContext());
     ll.setLayoutParams(new TableRow.LayoutParams(
                   LayoutParams.MATCH_PARENT,
                   LayoutParams.WRAP_CONTENT));
     ll.setOrientation(LinearLayout.VERTICAL);
     ll.setBackgroundDrawable(shape); 
 
         TextView data = new TextView(this);
         data.setText("asd");
         data.setBackgroundColor(Color.parseColor("#99cccc"));
         TextView data1 = new TextView(this);
         data1.setText("asd1");
         TextView data2 = new TextView(this);
         data2.setText("asd2");
           /* Add TextView to row. */
           ll.addView(data);
           ll.addView(data1);
           ll.addView(data2);
           tr.addView(ll);
     /* Add row to TableLayout. */
     tl.addView(tr,new TableLayout.LayoutParams(
           LayoutParams.MATCH_PARENT,
           LayoutParams.WRAP_CONTENT));
Gradler (109,780 포인트) 님이 2014년 1월 27일 답변
우와..저도 이걸로 헤매고 있었는데...감사합니다^^;
...